SDNU1311.Binomial Coeffcients

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值