How many HDU 1799 cycles? (Combined mathematics)

Source: Internet
Author: User

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)

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.