uva 11609 组合数学

#include <iostream>
#include <cstdlib>
#include <cstdio>
const int MOD = 1000000007;
typedef long long ll;
using namespace std;
ll N, T;
ll spow(ll x, ll n )
{
    if ( n == 0LL ) return 1LL;
    if ( n == 1LL ) return x % MOD;
    ll v = spow( x, n / 2LL );
    if ( n % 2LL == 1LL )
        return ((v * v) % MOD * x) % MOD;
    else return (v * v) % MOD;
}
int main()
{
    while ( cin >> T )
        for ( int t = 1 ; t <= T ; ++ t )
        {
            cin >> N;
            printf("Case #%d: %lld\n", t, spow(2LL, N - 1LL)*N % MOD);
        }
    return 0;
}


题意: 给出n个人, 从中选出k个人作为player, 每种组合都会有一个队长(captain), 同样的player, 只要队长不同那就算是不同的组合.


解题思路:1. sum( C(n, k)*C(k, 1) ) = sum( C(n, 1)*C(n-1, k-1) ) = n*sum( C(n-1, k-1) ) = n*2^(n-1);

你可能感兴趣的:(uva 11609 组合数学)