码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-01-26 00:07:45      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:acm   数学   

链接: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;
}



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

标签:acm   数学   

原文地址:http://blog.csdn.net/u013050857/article/details/43126031

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!