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)