您的位置:首页 > 其它

UVA 11609 (组合数学)

2016-06-07 22:52 302 查看
题意:求sigma(i*C(n, i)).

因为i*C(n, i) = i*n*(n-1)*...*(n-i+1)/i! = n*(n-1)*...*(n-2+1)/(i-1)! = (n-i+1)*C(n, i-1),

所以(i-1)*C(n,i-1)+i*C(n, i) = n*C(n, i-1),所以这个求和式的没两项都能合并,提出一个

n的公约数后,最后就是n*[C(n,0)+C(n,2)+C(n,4)+...] = n*2^(n-1).奇偶的情况是一样

的都是这个结果.



#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
const long long mod = 1e9+7;

long long n;

long long qpow (long long a, long long b) {
if (b == 0)
return 1;
long long ans = qpow (a, b>>1);
ans = ans*ans % mod;
if (b&1) ans = ans*a%mod;
return ans;
}

int main () {
int t, kase = 0;
cin >> t;
while (t--) {
cin >> n;
printf ("Case #%d: ", ++kase);
cout << (n*qpow (2, n-1))%mod << endl;
}
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: