zoukankan      html  css  js  c++  java
  • UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the game
    is that there is no limitation on the number of players in each team, as long as there is a captain in
    the team. (The game is totally strategic, so sometimes less player increases the chance to win). So the
    coaches who have a total of N players to play, selects K (1 ≤ K ≤ N) players and make one of them
    as the captain for each phase of the game. Your task is simple, just find in how many ways a coach
    can select a team from his N players. Remember that, teams with same players but having different
    captain are considered as different team.
    Input
    The first line of input contains the number of test cases T ≤ 500. Then each of the next T lines contains
    the value of N (1 ≤ N ≤ 109
    ), the number of players the coach has.
    Output
    For each line of input output the case number, then the number of ways teams can be selected. You
    should output the result modulo 1000000007.
    For exact formatting, see the sample input and output.
    Sample Input
    3
    1
    2
    3
    Sample Output
    Case #1: 1
    Case #2: 4
    Case #3: 12

    题意:给你一个n,n个人,标号为1~n,现在选若干人组成一队,并且选出一个队长,问说可以选多少种队伍,队长,人数,成员不同均算不同的队伍。

    题解:我们枚举选择k个人(1<=k<=n)

            答案就是: 1*c(n,1)+2*c(n,2)+.......+n*c(n,n);

       接着提出n

        化为:    n*(c(n-1,0)+c(n-1,1)+c(n-1,2)+......+c(n-1,n-1));

      答案就是:n*(2^(n-1));快速幂求解

    //meek///#include<bits/stdc++.h>
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <stack>
    #include <sstream>
    #include <vector>
    using namespace std ;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    #define fi first
    #define se second
    #define MP make_pair
    typedef long long ll;
    
    const int N = 110;
    const int inf = 99999999;
    const int MOD= 1000000007;
    
    ll quick_pow(ll x,ll p) {
        if(!p) return 1;
        ll ans = quick_pow(x,p>>1);
        ans = ans*ans%MOD;
        if(p & 1) ans = ans*x%MOD;
        return ans;
    }
    int main() {
        int T,cas=1;
        ll n;
        scanf("%d",&T);
        while(T--) {
            scanf("%lld",&n);
            printf("Case #%d: %lld
    ",cas++,n*quick_pow(2,n-1)%MOD);
        }
        return 0;
    }
    DAIMA

        

  • 相关阅读:
    快速傅里叶变换(FFT)
    【BZOJ】1005: [HNOI2008]明明的烦恼(prufer编码+特殊的技巧)
    【BZOJ】1030: [JSOI2007]文本生成器(递推+ac自动机)
    cf490 C. Hacking Cypher(无语)
    高精度模板2(带符号压位加减乘除开方封包)
    【BZOJ】1004: [HNOI2008]Cards(置换群+polya+burnside)
    【BZOJ】1500: [NOI2005]维修数列(splay+变态题)
    【BZOJ】1064: [Noi2008]假面舞会(判环+gcd+特殊的技巧)
    【BZOJ】1052: [HAOI2007]覆盖问题(贪心)
    【BZOJ】1028: [JSOI2007]麻将(贪心+暴力)
  • 原文地址:https://www.cnblogs.com/zxhl/p/5078443.html
Copyright © 2011-2022 走看看