您的位置:首页 > 其它

Poj 2249 Binomial Showdown

2013-06-16 17:54 381 查看
题目链接:http://poj.org/problem?id=2249

简单的组合题。

C(n,m) = C(n,m-1) * (n-m+1) / m.

C(n,m) = C(n,n-m).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>

using namespace std;

long long C(int n,int m)
{
m = m<(n-m) ? m : (n-m);
if(m == 0) return 1;
long long ans = 1;
for(int i=1;i<=m;i++)
{
ans = ans *(n-i+1)/i;
}
return ans;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n,m;
while(scanf(" %d %d",&n,&m)!=EOF)
{
if(n == 0 && m == 0) break;
printf("%lld\n",C(n,m));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: