1311.Binomial Coeffcients
Description
The binomial coefficientis
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.
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.
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;
}
这道题目要求计算C(n, k)模10000003,通过杨辉三角的性质来实现。利用C(n, k) = C(n-1, k-1) + C(n-1, k)进行递推,先生成杨辉三角的部分表,然后根据给定的n和k计算结果。"
101346025,1392973,Cucumber入门与Gherkin语法详解,"['测试框架', 'Cucumber', 'BDD实践', '自动化测试', 'Gherkin语法']
561

被折叠的 条评论
为什么被折叠?



