Number of cycles (M-brute force Solver, play table)

Source: Internet
Author: User


Number of Cycles

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

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

2 1 3) 2 3                

Sample Output

3 3Test Instructions:calculates the number of runs of a variable in a for loop. Analysis:1. Math problems, permutations and combinations. Formula: C (n,m) =c (n-1,m) +c (n-1,m-1)2. You need to select the number of m from the N number and increment the loop

Code:

1#include <cstdio>2#include <iostream>3 using namespacestd;4 5 intt[10000],m[ -],n[ -];6 inta[2005][2005];7 8 intMain ()9 {Ten     intT; Onescanf"%d",&T); Aa[0][0]=1;  -  -      for(intI=1; i<= -; i++)//Play Table the     {           -a[i][0]=1; -          for(intj=1; j<= -; j + +) -A[i][j]= (a[i-1][j]+a[i-1][j-1])%1007; +     } -  +      while(t--) A     {     at         intM,n; -scanf"%d%d",&m,&N);  -printf"%d\n", A[n][m]); -     } - return 0; -}
View Code

Number of cycles (M-brute force Solver, play table)

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.