UVA 11609

题目链接

想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数。

选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的。。。

搜了一下题解,先选队长Cn1,选一个人的时候Cn-1 0,选2个人的时候Cn-1 1这样就构成二项式系数了。

一约,n*2^n-1。。。最后,还忘了取模,错了好多次。。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <cmath>
 5 #include <ctime>
 6 #include <cstdlib>
 7 #include <iostream>
 8 using namespace std;
 9 #define LL long long
10 #define MOD 1000000007
11 LL fastmod(LL a,LL k)
12 {
13     LL b = 1;
14     while(k)
15     {
16         if(k&1)
17         b = a*b%MOD;
18         a = (a%MOD)*(a%MOD)%MOD;
19         k = k/2;
20     }
21     return b;
22 }
23 int main()
24 {
25     LL n,t,cas = 1;
26     cin>>t;
27     while(t--)
28     {
29         cin>>n;
30         cout<<"Case #"<<cas++<<": ";
31         cout<<(n*fastmod(2,n-1))%MOD<<endl;
32     }
33     return 0;
34 }

原文地址:https://www.cnblogs.com/naix-x/p/3382003.html