B 病毒扩散 组合数

题目链接:https://ac.nowcoder.com/acm/contest/5205/B

 自我感觉这个模型挺难想的。。。另外还有一种杨辉三角的解法。。也不是很懂。。

这道题在组合数方面需要用到逆元

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int w=1e6+5;
 5 const ll mod=998244353;
 6 ll fac[10005],ni[10005];
 7 ll quick(ll x,ll y)
 8 {
 9     ll ans=1;
10     while(y)
11     {
12         if(y&1)
13             ans=ans*x%mod;
14         x=x*x%mod;
15         y/=2;
16     }
17     return ans;
18 }
19 ll C(ll x,ll y)
20 {
21     ll ans=1;
22     ans=fac[x]*ni[y]%mod*ni[x-y]%mod;
23     return ans;
24 }
25 int main()
26 {
27     int i,j;
28     int n;
29     cin>>n;
30     fac[0]=1,ni[0]=1;
31     for(i=1;i<10005;i++)
32         fac[i]=fac[i-1]*i%mod;
33     ni[10004]=quick(fac[10004],mod-2);
34     for(i=10003;i>=0;i--)
35         ni[i]=ni[i+1]*(i+1)%mod;
36     while(n--){
37         int x,y,z;
38         scanf("%d%d%d",&x,&y,&z);
39         //x++,y++,z+=2;
40         int u=x+y;
41         if(u>z)
42         {
43             puts("0");
44             continue;
45         }
46         ll ans=C(z,u)*C(u,x)%mod;
47         printf("%lld\n",ans);
48     }
49     return 0;
50 }
View Code

猜你喜欢

转载自www.cnblogs.com/pangbi/p/12900731.html