1. 程式人生 > >2018 Multi-University Training Contest 8

2018 Multi-University Training Contest 8

ostream num opened lose -- max class esp can

1001:

公式題,可以用容斥和隔板法推出來。

技術分享圖片

技術分享圖片
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int MAX=3e5+5;
const long long mod=998244353;
long long fac[MAX],rev[MAX];
long long qp(long long p,long long q)
{
    int cnt=1;
    while(q>0)
    {
        if(q%2==1) cnt=(cnt*p)%mod;
        q
/=2; p=(p*p)%mod; } return cnt%mod; } long long C(long long a,long long b) { if(a<0||b<0) return 0; long long flag=fac[a]; return ((fac[a]*rev[b])%mod*rev[a-b])%mod; } long long n,m,k; long long solve(long long sum,long long num,long long p) { if(sum==0) return 1;
long long cnt=0; int i,j; for(i=0;i<=num;i++) { long long a=C(num,i),b=C(sum-p*i-i+num-1,sum-p*i-i); long long flag=(C(num,i)*C(sum-p*i-i+num-1,sum-p*i-i))%mod; if(i%2==1) flag=(mod-flag)%mod; cnt=(cnt+flag)%mod; } return cnt; } int main() {
int i,j; int t; scanf("%d",&t); fac[0]=1; rev[0]=1; for(i=1;i<MAX;i++) { fac[i]=(fac[i-1]*i)%mod; rev[i]=qp(fac[i],mod-2); } while(t--){ scanf("%lld%lld%lld",&n,&m,&k); long long ans=solve(k,m,n-1); printf("%lld\n",ans); } return 0; }
View Code

1002:

1004:

1005:

1010:

1011:

1012:

2018 Multi-University Training Contest 8