That day we promised convention (combinatorics, DP)

Read the topic title name deeply skeptical people are not falling out of love, then the question of torture us. Then pleasant this problem called violence, and finally somehow wa20, sad .....

In fact, this problem is not difficult to think positive solution, if the DP engage in violence out positive solutions but also the difference is not where to go,

We found that if this question of violence

D enumerator i.e. one day, another biscuit gave enumerate the current number j, then there is a layer enumerate the number of biscuit layer, (of course also be omitted by the prefix and the one-dimensional)

However, we observe the data range, and found the big D! ! ! ! ! ! !

Obviously not appear enumeration D

Apparently there is a character, if you have N biscuits, then to a maximum of N days, will give a day to complete.

So we first dimension to enumerate N, certain to represent each day

Statistics last answer (i: 1 ~ N) f [i] [N] * C (D, i); can

(D In this problem too large, it can not use inverse element, use recursive O (n) request, * (Di) To modulus, or will storm)

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<string>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define ll long long
 8 using namespace std;
 9 #define MAXN 2010
10 const ll mod=998244353;
11 ll f[MAXN][MAXN];
12 ll N,D,M;
13 ll ni[MAXN],ni_c[MAXN];
14 ll a[MAXN][MAXN];
15 ll max1(ll x,ll y)
16 {
17    return (x>y)?x:y;
18 }
19 ll min1(ll x,ll y)
20 {
21    return (x<y)?x:y;
22 }
23 void work()
24 {
25    f[0][0]=1;a[0][0]=1;   
26    for(ll i=1;i<=N;++i)
27    {
28        ll R=min(N,(M-1)*i);   
29        for(ll j=1;j<=N;++j)
30        {
31            a[i-1][j]=(a[i-1][j-1]+f[i-1][j]+mod)%mod;
32        }   
33        for(ll j=i;j<=R;++j)
34        {
35            ll L=max1(i-1,j-M+1);
36            /*for(ll k=L;k<=j-1;++k)
37            {
38               f[i][j]=(f[i][j]+f[i-1][k])%mod;
39            }*/
40            f[i][j]=(f[i][j]%mod+(a[i-1][j-1]-a[i-1][L-1]+mod)%mod+mod)%mod;
41            //printf("f[%lld][%lld]=%lld\n",i,j,f[i][j]);
42        }
43    }
44    ll sum=0ll;ll ans=1ll;
45    for(ll i=1;i<=N;++i)
46    {
47       if(i>D)continue;
48       ans=(ans*((D-i+1)%mod)+mod)%mod;
49       sum=(sum+(f[i][N]*(ans*ni_c[i]%mod+mod)+mod)%mod+mod)%mod;
50       //printf("f=%lld C=%lld\n",f[i][N],C(D,i));
51    }
52    printf("%lld\n",sum%mod);
53 }
54 int main()
55 {
56  //  freopen("text.in","r",stdin);
57  //  freopen("wa.out","w",stdout);
58    ni_c[1]=1;ni[1]=1;
59    ni_c[0]=1;ni[0]=1;
60    for(ll i=2;i<=2000;++i)
61    {
62        ni[i]=((mod-mod/i)*ni[mod%i])%mod;
63        ni_c[i]=(ni_c[i-1]*ni[i])%mod;
64    }
65    while(cin>>N>>D>>M)
66    {
67       if(N==0&&D==0&&M==0)break;
68       memset(f,0,sizeof(f));
69       memset(a,0,sizeof(a));
70       work();
71    }
72 }
View Code

 

Guess you like

Origin www.cnblogs.com/Wwb123/p/11221064.html