0
点赞
收藏
分享

微信扫一扫

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


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



举报

相关推荐

0 条评论