Description
We know that in programming, we often need to take into account the complexity of time, especially for the loop part. For example
If the code appears
for (i=1;i<=n;i++) OP;
Then do the N-Times op operation if the code appears
fori=1;i<=n; i++)
for (j=i+1;j<=n; j + +) OP;
Then do N (n-1)/2 op operation.
Now you are given an M-layer for loop operation, and each time the start value of the variable in for is the starting value of the previous variable +1 (the first variable starts with a value of 1), the terminating value is an input n, and the last OP has a total amount of computation.
Input
There are T group case,t<=10000. Each case has two integers m and n,0<m<=2000,0<n<=2000.
Output
For each case, output a value that represents the total amount of computation, perhaps the number is large, then you only need to output the remainder of the 1007 left.
Sample Input
21 32 3
Sample Output
33 Problem-solving ideas: In fact, the meaning of this topic is to seek the input of the m,n permutation combination, that is, C (m,n), there is a formula C (m,n) =c (m,n-1) +c (m-1,n-1), there is a clear continuous multiplication will overflow, so we have to use the law of violence enumeration, put in an array, so convenient. Program code:
# include<cstdio>using namespacestd;intc[2005][2005];void inch(){ intN, m; c[0][0] =1; for(n =1; N <= -; n++) {c[n][0] =1; for(M =1; M <= -; m++) C[n][m]= (C[n-1][M] + c[n-1][m-1]) %1007; }}intMain () {intt, N, M;inch(); scanf ("%d", &t); while(t--) {scanf ("%d%d", &m, &N); printf ("%d\n", C[n][m]); } return 0;}
Hdu 1799 cycles How many times?