zoukankan      html  css  js  c++  java
  • 求组合

    #include <iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    #include<string>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    typedef long int64;
    int64 work(int64 n,int64 k)
    {
        if (k>n/2)k=n-k;
        int64 a=1,b=1;
        for (int i=1;i<=k;i++)
        {
            a*=n+1-i;
            b*=i;
            if (a%b==0)a/=b,b=1;
        }
        return a/b;
    }
    int main()
    {
        int n,k;
        while (~scanf("%d%d",&n,&k)&&n)
        {
            printf("%ld
    ",work(n,k));
        }
        return 0;
    }
    

      

     

    #include <iostream>
    using namespace std;
    int work(int n,int k)
    {
        return k==0?1:work(n,k-1)*(n-k+1)/k;
    }
    int main()
    {
        int n,k;
        while (scanf("%d%d",&n,&k)==2)
        {
            printf("%d
    ",work(n,k));
        }
        return 0;
    }
    

      

  • 相关阅读:
    python10.31
    python10.29
    python10.28
    python10.27
    python10.25
    python10.24
    python10.23
    四边形不等式与决策单调
    0x57~0x59
    0x55~0x56
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3466540.html
Copyright © 2011-2022 走看看