数学方法推一下:
我们枚举出t=1-5秒内的变化人数图
当t=1时:
1
1 1
t=2时:
1
2 2
1 2 1
t=3s
1
3 3
3 6 3
1 3 3 1
t=4时
1
4 4
6 12 6
4 12 12 4
1 4 6 4 1
我们发现当时间为t时,第n斜行的数为 ,所以每个位置的感染者数也就出来了,自己推一下也很简单
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=5005;
const int mod=998244353;
int ans[maxn][maxn];
int cnt[10000];
int main(){
ans[0][0]=1,ans[1][0]=1,ans[0][1]=1;
for(int i=1;i<5001;++i){ans[i][0]=1,ans[0][i]=1;}
for(int i=1;i<5001;++i)
for(int j=1;j<5001;++j)
ans[i][j]=(ans[i-1][j]+ans[i][j-1])%mod;
int n;
cin>>n;
while(n--){
int x,y,t;
cin>>x>>y>>t;
if(x+y>t){
cout<<"0"<<endl;
continue;
}
ll res=(ll)ans[t-x-y][x+y]*ans[x][y]%mod;
cout<<res<<endl;
}
}



京公网安备 11010502036488号