# snnu1111 (sub-sequence summation)

Source: Internet
Author: User

1111: Sub-sequence summation time limit:3 Sec Memory limit:64 MB
Submit:10 Solved:2
[Submit] [Status] [Web Board]  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[i]=1; f=pow (2, N); //cout<<f<<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)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.