您的位置:首页 > 其它

ZOJ 1938 Binomial &&poj 2249 (Binomial Showdown )(睡前一水)

2015-01-25 23:23 411 查看
链接:click here

题意:

In how many ways can you choose k elements out of n elements, not taking order into account? Write a program to compute this number.

给你整数n和k,让你求组合数c(n,k)。

代码:

#include <cstdio>
#include <cstring>
#include <math.h>
typedef long long LL;
LL  ans,n,k;
int main()
{
    while(scanf("%lld%lld",&n,&k),n)
    {
        ans=1;
        if(k == 0)
        {
            printf("1\n");
            continue;
        }
        k=n-k>k?k:n-k;
        //if(k>n-k)k=n-k;
        for(int i=1; i<=k; i++)
        {
            ans=ans*(n-i+1)/i;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: