UVa 11609 组队(快速幂)

https://vjudge.net/problem/UVA-11609

题意:

有n个人,选一个或多个人参加比赛,其中一名当队长,有多少种方案?如果参赛者完全相同,但队长不同,算作不同的方案。

思路:

之后就是快速幂处理。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<vector>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 
10 typedef long long LL;
11 
12 const int MOD=1000000007;
13 
14 LL n;
15 
16 LL pow(LL n)
17 {
18     LL res=1,base=2;
19     while(n)
20     {
21         if(n&1)
22             res=(res*base)%MOD;
23         base=(base*base)%MOD;
24         n>>=1;
25     }
26     return res;
27 }
28 
29 
30 int main()
31 {
32     //freopen("D:\input.txt","r",stdin);
33     int T;
34     scanf("%d",&T);
35     for(int kase=1;kase<=T;kase++)
36     {
37         scanf("%lld",&n);
38         LL ans = pow(n-1);
39         printf("Case #%d: %lld
",kase,(n*ans)%MOD);
40     }
41 }
原文地址:https://www.cnblogs.com/zyb993963526/p/6718669.html