您的位置:首页 > 其它

ZOJ 3556 How Many Sets I

2015-10-01 13:19 288 查看

How Many Sets I

Time Limit: 2000ms
Memory Limit: 65536KB
This problem will be judged on ZJU. Original ID: 3556
64-bit integer IO format: %lld Java class name: Main

Give a set S, |S| = n, then how many ordered set group (S1, S2, ..., Sk) satisfies S1 ∩ S2 ∩ ... ∩ Sk = ∅. (Si is a subset of S, (1 <= i <= k))

Input

The input contains multiple cases, each case have 2 integers in one line represent n and k(1 <= k <= n <= 231-1), proceed to the end of the file.

Output

Output the total number mod 1000000007.

Sample Input

1 1
2 2

Sample Output

1
9

Source

ZOJ Monthly, October 2011

Author

QU, Zhe

解题:

从子集中选k个的有序组合个数(子集可重复被选中)有 $(2^n)^k=2^{n\times k}$;

故总数为$S=2^{n\times k}$;

$设S(x)为k个集合的有序组合的个数,这些集合都包含至少一个x。$

$S(x_1 \& x_2)为k个集合的有序组合的个数,这些集合都包含至少一个x_1和x_2$

$S(x_1\& x_2\& x_3...x_k)为k个集合的有序组合的个数,这些集合都包含至少一个x_1,x_2...x_k。$

$而 S(x)=(2^{n-1})^k =2^{(n-1)\times k};$

$S(x_1 \& x_2)=(2^{n-2})^k=2^{(n-2)\times k};$

$S(x_1\& x_2 \&...\& x_i)=(2^{n-i})^k=2^{(n-i)\times k};$

由容斥原理知,我们要得到的就是

$S-(n,1)\times S(x) + (n,2)\times (S(x_1\& x_2)-(n,3)\times (S(x_1\& x_2\&x_3)+....(-1)^i\times (n,i)\times S(x_1\& x_2\&...x_i)...(-1)^n\times (n,n)\times S(x_1\& x_2...\& x_n);$

$化简得ans=(2^K-1)^N;$

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL mod = 1000000007,n,k;
LL quickPow(LL base,LL index){
LL ret = 1;
while(index){
if(index&1) ret = ret*base%mod;
index >>= 1;
base = base*base%mod;
}
return ret;
}
int main(){
while(~scanf("%lld%lld",&n,&k))
printf("%lld\n",quickPow(((quickPow(2,k) - 1)%mod + mod)%mod,n));
return 0;
}


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