1111: Sub-sequence summation time limit:3 Sec Memory limit:64 MB
Submit:10 Solved:2
[Submit] [Status] [Web Board] [Edit] Description
Give n numbers, respectively, 1,2,3,......,n. The t number is selected, and the number of the T number and the scheme for X is ft,x. Give the M. Output the following values:
The data satisfies n <= 20000,m <= min (n).
Input
The first line input T indicates the number of rows for the test data. Next T line, two digits N, m per line. T <= 20.
Output
For each set of test data, output one line.
Sample Input2Sample Output -HINT
Source
2015 College student Program design competition in Shaanxi province. C
Use d[t][x] to represent t numbers and the number of schemes for X, and the maximum number in this T number is no more than N. Core idea: To give d[t][x] each number minus one, become d[t][x-t],d[t][x] should be equal to d[t][x-t]. If the minimum number in this T number is 1, minus 1, the minimum number becomes 0, which is equivalent to t-1 number, d[t-1][x-t], However, both cases are not considered, the maximum number is not more than N, assuming D[t][x-t] The largest number is N, give this t number each plus 1, then the maximum number is n+1, more than N, so, to remove n+1, the largest number, minus this situation, equivalent to lose d[t-1][x-t ]. There is also a pit is a+b-c, because to take the mold, so a+b may be less than C, (A+b-c+mod)%mod; (D%mod+mod)%mod;
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>using namespacestd;#defineMAXN 21000#defineLL Long Long#defineMOD 1000000007intn,m; LL answer; LL d[ the][maxn* the]; LL f[ the];voidinit () {memset (d,0,sizeof(d)); for(intI=1;i< the; i++) F[i]=1;} LL Pow (intAintb) {LL ans=1; for(intI=1; i<=b;i++) {ans= (ans*a)%MOD; } returnans;}voidsolve () { for(intI=1; i<=n;i++) d[1][i]=1; f[1]=pow (2, N); //cout<<f[1]<<endl; for(intt=2; t<=m;t++) { for(intx=1;x< (t*n); x + +) {D[t][x]= (d[t][x-t]+d[t-1][x-t]-d[t-1][x-(n+1)] + MOD)%MOD; F[t]= (f[t]* (d[t][x]+1))%MOD; //printf ("%d%d%d\n", t,x,d[t][x]); } //The minimum value is either 1 or not 1,//when the minimum value is 1 o'clock, the maximum value may be n, minus d[t-1][x-(n+1)]; //when the minimum value is not 1, the maximum value may also be N, which requires subtracting d[t-1][x-(n+1)];//because these two cases are mutually exclusive, you need to subtract up to 1 times//cout<<endl; //While (f[t]<0)//cout<<f[t]<<endl;} answer=0; for(intt=1; t<=m;t++) { //printf ("F%d%d\n", t,f[t]);Answer= (Answer+f[t])%MOD; Answer=answer%MOD; } //While (answer<0)printf"%lld\n", answer%MOD);}intMain () {//cout<< ( -5)%3<<endl; intT; scanf ("%d",&t); while(t--) {init (); scanf ("%d%d",&n,&m); Solve (); } return 0;}
snnu1111 (sub-sequence summation)