Hdu 1799 there are formulas. Never taught. C (n) (m) =c (n-1) (m) +c (n-1) (m-1)

Source: Internet
Author: User

How many times are the loops?

Time limit:3000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 3096 Accepted Submission (s): 1144

Problem 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 a for (i=1;i<=n;i++) OP appears in the code; Then do N-Times op, 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 has T group case,t<=10000. Each case has two integers m and n,0<m<=2000,0<n<=2000.

Output for each case, outputs a value that represents the total amount of computation, perhaps a large number, then you only need to output the remainder of the 1007 left.

Sample Input21 32 3


Sample Output33ps:c (N) (m) =c (n-1) (m) +c (n-1) (m-1);#include "stdio.h"
int c[2005][2005];
int main ()
{
int n,m,t;
C[0][0]=1;
for (n=1;n<=2000;n++)
{
C[n][0]=1;
for (m=1;m<=2000;m++)
C[n][m] = (C[n-1][m] + c[n-1][m-1])% 1007;
}
scanf ("%d", &t);
while (t--)
{
scanf ("%d%d", &m,&n);
printf ("%d\n", C[n][m]);
}
return 0;
}

Hdu 1799 has a formula: Never taught. C (n) (m) =c (n-1) (m) +c (n-1) (m-1)

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.