How many cycles?
Time Limit: 3000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2821 accepted submission (s): 1022
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
List the table Search rules on the presentation paper.
#include <stdio.h>#define maxn 2002int dp[maxn][maxn];void count(){int i, j;for(i = 1; i < maxn; ++i)dp[i][1] = i % 1007;for(i = 1; i < maxn; ++i)for(j = 2; j < maxn; ++j)dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % 1007;}int main(){int n, m, t;count();scanf("%d", &t);while(t--){scanf("%d%d", &m, &n);printf("%d\n", dp[n][m]);}return 0;}