Use the combination formula C (n,m) =c (n-1,m) +c (n-1,m-1). That is, from the number of N to select the number of M, in an incremental way in each layer of the loop.
Yang Hui triangle + two-term theorem, there is really a "meaning" of a problem. To tell the truth, not original. Excuse me.....
The main idea: a cyclic structure has m-layer, the first layer is 1~n, after each additional layer, the initial value of the cyclic variables are added 1 on the basis of the previous layer.
For example: The first layer is 1~n, then the second layer is 2~n, and so on. Find the number of cycles of the M layer (answer to 1007 modulo).
Sample Input
2//Number of test cases T
1 3//m and N
2 3
Sample Output//Cycle times
3
3
#include <iostream>#include<cstdio>using namespacestd;intt,m,n,i,j;intans[2001][2001];voidSlove () {ans[0][0]=1; for(i=1; i<= -; i++) {ans[i][0]=1; for(j=1; j<= -; j + +) Ans[i][j]= (ans[i-1][j-1]+ans[i-1][J])%1007; } }intMain () {slove (); CIN>>T; while(t--) {cin>>m>>N; printf ("%d\n", Ans[n][m]); } return 0;}
2016HUAS_ACM Summer Camp 4 A-recursion