首页 > 代码库 > POJ 2249

POJ 2249

简单求组合数,直接运用公式。注意C(n,k)=C(n,n-k)。

#include <iostream>#include <cstdio>#include <algorithm>#define LL __int64using namespace std;LL myc(LL n, LL r){	LL sum=1;	for(LL i=1;i<=r;i++)	sum=sum*(n+1-i)/i;	return sum;}int main(){	LL n,r;	while(scanf("%I64d%I64d",&n,&r),n||r){		r=r>n-r?n-r:r;		LL res=myc(n,r);		printf("%I64d\n",res);	}	return 0;}

  

POJ 2249