计算组合数C(n,m)
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
C(n,m)=n!/(m! * (n-m)!).(0<=n,m<=10^8且m<=n,该题结果保证在int范围之内)。
输入
第一行是一个正整数t,下面t行每行有两个整数n和m。
输出
对于每一行输入,分别对应输出组合数C(n,m)的值
示例输入
3 1 1 2 1 3 2
示例输出
1 2 3
来源
moon
#include<bits/stdc++.h>
using namespace std;
long long zhs(long long n,long long m)
{
if (n==m||!m)
return 1;
else
return zhs(n-1,m)+zhs(n-1,m-1);
} //递归求C(n,m),递归公式:c(n,m)=c(n-1,m-1)+c(n-1,m)
int main()
{
long long t,n,m;
cin>>t;
while (t--)
{
cin>>n>>m;
cout<<zhs(n,m)<<endl;
}
return 0;
}