Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1799
Problem description we know that in programming, we often need to consider the time complexity, especially for the loop part. For example,
If
For (I = 1; I <= N; I ++) OP;
N op operations are performed.
Fori = 1; I <= N; I ++)
For (j = I + 1; j <= N; j ++) OP;
Then, N * (n-1)/2 op operations are performed.
Now we know that there are m-layer for loop operations, and the starting value of each for variable is the starting value of the previous variable + 1 (the starting value of the first variable is 1 ), the end value is an input N, and the total calculation amount of the op is asked.
Input has T group case, T <= 10000. Each case has two integers, M and N, 0 <m <= 2000, 0 <n <=. output outputs a value for each case, indicating the total calculation amount. Maybe this number is large, you only need to output the remainder except 1007. Sample Input
21 32 3
Sample output
33
Authorwangye source2008 "insigma International Cup" Zhejiang Collegiate Programming Contest-warm up (4)
PS:
Sum of combinations: C (n, m) = C (n-1, m) + C (n-1, m-1 );
The Code is as follows:
#include <cstdio>#include <cstring>int dp[2017][2017];void OP(){ for(int i = 1; i <= 2000; i++) { dp[i][0] = 1; dp[i][1] = i%1007; } for(int i = 2; i <= 2000; i++) { for(int j = 1; j <= 2000; j++) { dp[i][j] = (dp[i-1][j]+dp[i-1][j-1])%1007; } }}int main(){ int t; int n, m; OP(); scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); printf("%d\n",dp[n][m]); } return 0;}
How many HDU 1799 cycles? (Combined mathematics)