/***
容斥原理
考虑总的种数减去集合不为空的种数。
首先是总的种数:每个集合有2^n个子集,总共k的集合
所以总数就是2^(n*k)
再考虑集合不为空的情况,
首先考虑最后交集只有一个元素,这种情况总共有(2^(n-1))^k种
交集有两个元素(2^(n-2))^k种
交集有t个元素(2^(n-t))^k种
根据容斥原理,总共集合不为空的情况有
C(n,1) * (2^(n-1))^k - C(n,2) * (2^(n-2))^k + ... + C(n,t) * (-1)^(t+1) * (2^(n-t))^k
= p
所以最后答案就是 2^(n*k) - p = (2^k - 1 )^n
***/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
const int M = 1000000007;
LL n,k;
LL pow_mod(LL a,LL b,LL c){
LL res =1;
while(b){
if(b&1) res = res*a%c;
b >>= 1;
a = a*a%c;
}
return res;
}
int main(){
while(cin >> n >> k){
LL ans = pow_mod(pow_mod(2,k,M)-1,n,M);
cout << ans << endl;
}
return 0;
}
zoj 3556 How Many Sets I - 容斥原理
最新推荐文章于 2017-08-25 09:39:24 发布