题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1799
2 1 3 2 3
3 3
PS:
组合求和:C(n, m) = C(n-1, m)+C(n-1, m-1);
代码如下:
#include <cstdio> #include <cstring> int dp[2017][2017]; void OP() { for(int i = 1; i <= 2000; i++) { dp[i][0] = 1; dp[i][1] = i%1007; } for(int i = 2; i <= 2000; i++) { for(int j = 1; j <= 2000; j++) { dp[i][j] = (dp[i-1][j]+dp[i-1][j-1])%1007; } } } int main() { int t; int n, m; OP(); scanf("%d",&t); while(t--) { scanf("%d%d",&m,&n); printf("%d\n",dp[n][m]); } return 0; }
原文地址:http://blog.csdn.net/u012860063/article/details/39321015