计算组合数

计算组合数

Time Limit: 1000MS Memory Limit: 32768KB

Problem Description

计算组合数。C(n,m),表示从n个数中选择m个的组合数。
计算公式如下:
若:m=0,C(n,m)=1
否则, 若 n=1,C(n,m)=1
             否则,若m=n,C(n,m)=1
                         否则 C(n,m) = C(n-1,m-1) + C(n-1,m).

 

Input

第一行是正整数N,表示有N组要求的组合数。接下来N行,每行两个整数n,m (0 <= m <= n <= 20)。

Output

输出N行。每行输出一个整数表示C(n,m)。

Example Input

32 13 24 0

Example Output

231
#include <iostream>
#include<math.h>
#include<cstdio>
using namespace std;
int answer(int  a,int b)
{
     if(b==0||a==1)
        return 1;
     else if(b==a)
        return 1;
     else
        return answer(a-1,b-1)+answer(a-1,b);
}
int main()
{
       int n;
       cin>>n;
       int t,c;
       while(n--)
       {
           cin>>t>>c;
            cout<<answer(t,c)<<endl;
       }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值