zoukankan      html  css  js  c++  java
  • Uva 11609 Teams (组合数学)

    题意:有n个人,选不少于一个人参加比赛,其中一人当队长,有多少种选择方案。

    思路:我们首先C(n,1)选出一人当队长,然后剩下的 n-1 人组合的总数为2^(n-1),这里用快速幂解决

    代码:

    #include <iostream>
    #define ll long long
    using namespace std;
    const ll mod = 1000000007;
    
    ll qmod(ll a, ll b)
    {
        ll ans=1;
        while(b)
        {
            if(b&1)
            {
                ans=(ans*a)%mod;
            }
            b=b/2;
            a=(a*a)%mod;
        }
        return ans;
    }
    
    int main()
    {
        int t,i=0;
        cin>>t;
        while(t--)
        {
            ll n;
            i++;
            cin>>n;
            ll ans=n%mod;
            ans=(n*qmod(2,n-1))%mod;
            cout<<"Case #"<<i<<": ";
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    备用
    Python进阶
    *args 和 **kwargs
    C语言
    【Pythno库】-Re
    【C语言】-struct
    Django By Example
    字符串
    Python库
    【Keil】Keil5-改变字的大小和颜色
  • 原文地址:https://www.cnblogs.com/simplekinght/p/6161051.html
Copyright © 2011-2022 走看看