Description
The binomial coefficient
is the number of ways of picking k unordered outcomes from n possibilities, also known as a combination or combinatorial number.
Give n and k, you are required to calculate
mod 10000003.
Input
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 calculate
mod 10000003.
Output
For each test case, output one line containing
mod 10000003.
Sample Input
3
1 1
10 2
954 723
Sample Output
1
45
3557658
组合数用杨辉三角进行运算,一劳永逸喔。
a[i][j]=a[i-1][j]+a[i-1][j-1].
ac代码:
#include <bits/stdc++.h>
using namespace std;
long long n,k;
int mod=10000003;
long long a[1001][1001];
void calculate(){
a[0][0]=1;
for(int i=0;i<1001;i++){
a[i][0]=1;
a[i][i]=1;
for(int j=1;j<i;j++){
a[i][j]=(a[i-1][j]+a[i-1][j-1])%mod;
}
}
return;
}
int main(){
cin>>c;
calculate();
while(c--){
cin>>n>>k;
cout<<a[n][k]<<endl;
}
return 0;
}