算法是n!/(m!*(n-m)!)
[ 本帖最后由 jiangwu10057 于 2010-1-30 14:19 编辑 ]
[ 本帖最后由 jiangwu10057 于 2010-1-30 14:19 编辑 ]
#include <stdio.h> #define N 1007 int fun(int ,int ,int ,int); int main(void) { int t,m,n; scanf("%d",&t); while(t--) { scanf("%d %d",&m,&n); printf("%d\n",fun(m,n,1,0)); } return 0; } int fun(int m,int n,int i,int sum) { int j; if(!m) { return sum; } else { for(j=i;j<=n;++j) { ++sum; } return fun(m-1,n,i+1,sum%N); } }
#define N 1007 int test(int m, int n) { int i, j, k; int *arr = new int[n + 1]; for (i = 1; i <= n; i++) arr[i] = 1; for (i = 2; i <= m; i++) { for (j = n; j > 0; j--) { arr[j] %= N; if (arr[j] != 0) { for (k = j + 1; k <= n; k++) arr[k] += arr[j]; } arr[j] = 0; } } int count = 0; for (i = 1; i <= n; i++) { count += arr[i]; } count %= N; delete []arr; return count; }