unsigned int comb(unsigned a,unsigned b)
{
if(b > a-b)
b= a-b;
double result = 1;
while(b>0)
{
result *= (double)a / (double) b;
//cout<<"result:"<<result<<endl;
--a;
--b;
}
return ( unsigned int)(result + 0.5); //四舍五入
}
一个求组合数的函数
#include <iostream>
#include <stdio.h>
using namespace std;
//C(a,b)
//
unsigned int comb(unsigned a,unsigned b)
{
if(b > a-b)
b= a-b;
double result = 1;
while(b>0)
{
result *= (double)a / (double) b;
//cout<<"result:"<<result<<endl;
--a;
--b;
}
return ( unsigned int)(result + 0.5);
}
int main()
{
unsigned int m,n;
while(cin>>m>>n)
{
if(m==0&&n==0)
break;
cout<<comb(m+n,m)<<endl;
}
}