ZOJ 3556 How Many Sets I
2015-10-01 13:19
288 查看
How Many Sets I
Time Limit: 2000msMemory 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 2011Author
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
相关文章推荐
- java中对字符串的基本操作
- (通俗易懂)自定义代理 :传递(参数)
- TCP浅谈(上)
- php move_uploaded_file()函数
- easyui 之 data-option
- USACO 2.2 Subset Sums (DP动态规划)
- 【QT5学习历程】
- 浅谈javascript的函数节流
- Coreseek:常见的问题2
- Y2K Accounting Bug(二进制+枚举)
- C#yield return和yield break函数执行逻辑理解
- 原型模式实现
- iOS_动态插入或删除行
- Service Manager流程,派BC_REPLY,唤醒FregServer流程,返回BR_TRANSACTION_COMPLETE,睡眠等待proc->wait
- python可变交换性能优化
- RTB广告展示分步说明
- JSONP
- js性能优化的措施
- Win32和MFC项目如何输出调试信息到VS的调试窗口
- javaAPI文档翻译之Java.io.File