How many hdu1799 cycles? [Finding Rules]

Source: Internet
Author: User
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;}


 

Contact Us

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.