排列组合

来源:互联网 发布:2017淘宝开店照片示范 编辑:程序博客网 时间:2024/06/03 14:54
#include <cstdio>#include <cstdlib>#include <iostream>#include <set>#include <cmath>#include <string>#include <cstring>#include <algorithm>#include <cctype>#include <queue>using namespace std;typedef long long ll;ll arrange(ll k,ll n)//排列{    if(k==0) return 1;    if(k==1) return n;    ll sum=1;    for(int i=0;i<k;i++)        sum*=n-i;    return sum;}ll comb(ll k,ll n)//组合{    if(k==0) return 1;    if(k==1) return n;    return arrange(k,n)/arrange(k,k);}int main(){    int n,k;    while(cin>>n>>k)        printf("%lld\n",comb(k,n));}

0 0
原创粉丝点击