SDNU 1311.Binomial Coeffcients 杨辉三角算组合数

这道题目要求计算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语法']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


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.


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 calculatemod 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


    简单说这题就是求组合数,给出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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值