ZOJ 1938 Binomial & & poj 2249 (Binomial Showdown) (잠 자기 전 물)

768 단어 수학.ACM
링크: 여 기 를 클릭 하 십시오
제목:
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
"); 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
",ans); } return 0; }

좋은 웹페이지 즐겨찾기