HDU 1799 cycles How many times? Tips for solving problems

Source: Internet
Author: User

Original question

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 the code appears
for (i=1;i<=n;i++) OP;
Then do the N-Times op operation 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

There are T group case,t<=10000. Each case has two integers m and n,0<m<=2000,0<n<=2000.

Output

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

Sample Input

21 32 3

Sample Output

33 My Code:
#include <iostream>#include<cstdio>using namespacestd;intch[2500][2500];intMain () {intI, J;  for(i =1; I <= -; i++) {Ch[i][i]=1; ch[i][1] = i%1007; }          for(i =2; I <= -; i++)         for(j =2; J <= I; J + +) Ch[i][j]= (Ch[i-1][J]%1007+ Ch[i-1][j-1] %1007) %1007; intT; CIN>>T;  while(t--)     {         intm, N; scanf ("%d%d", &m, &N); cout<< Ch[n][m] <<Endl; }    return 0;}
View Code

HDU 1799 cycles How many times? Tips for solving problems

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.