1311.Binomial Coeffcients
Description
The binomial coefficientis

Give n and k, you are required to calculate mod 10000003.
The input contains several test cases. The first line of the input contains one positive integer, c, denoting the number of test cases.
Each of the following c lines contains two integers, n(0<=n<=1000) and k (0<=k<=n), denoting that you are required to calculatemod 10000003.
For each test case, output one line containing mod 10000003.
3
1 1
10 2
954 723
Sample Output
1
45
3557658
简单说这题就是求组合数,给出n,k,求C(n,k)。其实求组合数一直不太会怎么求快= =搜了下可以通过C(n,m)=C(n-1,m-1)+C(n-1,m)的方法来得到组合数,就是杨辉三角的方法来打印出组合数,然后先写一个函数打出来表就好了。
下面AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const long long mod=10000003;
long long a[1005][1005];
int Combination(int n)
{
int i,j;
a[0][0]=1;
for(i=0;i<=n;i++)
{
a[i][0]=a[i][i]=1;
for(j=1;j<i;j++)
{
a[i][j]=(a[i-1][j-1]+a[i-1][j])%mod;
}
}
return 0;
}
int main()
{
int T;
int n,k;
Combination(1000);
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
cout<<a[n][k]<<endl;
}
return 0;
}