题意
hdkk 有 种颜色的珠子,每种珠子有 颗,他可以选出任意颗珠子串成一串项链。
每种珠子有一个漂亮值 ,hdkk 认为项链有一个美丽度,若第 种珠子在项链中有 颗并且 ,则这串项链的美丽度会加上 。
现在他想知道,所有不同的项链的美丽度总和是多少,请你求出答案,并对 取模。
思路
设 为所有 的和。
二项式定理推导一下:
原式化简为:
二项式定理进一步化简:
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 2e5 + 2, mod = 1e9 + 7;
int n;
ll a[N], v[N], sum;
ll ans;
ll po(ll a, ll b, ll mod){
ll ans = 1;
while(b){
if(b & 1){
ans = ans * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return ans;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
sum += a[i];
}
for(int i = 1; i <= n; i ++){
cin >> v[i];
}
for(int i = 1; i <= n; i ++){
ans = (ans + (po(v[i] + 1, a[i], mod) - 1 + mod) % mod * po(2, sum - a[i], mod) % mod) % mod;
}
cout << ans;
return 0;
}