ZOJ 3556 How Many Sets I
How Many Sets I
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
- 题意:
- 个数为n的集合,从中选出K个子集使得他们的交集为空的个数。
子集可以重复选
- 考虑1个元素
它在k子集里的数目为2^k
其中有一种是k个子集都有这个元素,他们这k个子集的交集就不为空
所以1个元素k个子集交集为空的数目 有(2^k)-1 种
那么n个元素就是((2^k)-1)^n
- #include<cstdio>
- using namespace std;
- typedef long long LL;
- const LL mod=;
- LL n,k;
- LL pow(LL a,LL b)
- {
- LL r=;
- while(b)
- {
- if(b&) r*=a,r%=mod;
- b>>=; a*=a; a%=mod;
- }
- return r;
- }
- int main()
- {
- while(scanf("%lld%lld",&n,&k)!=EOF)
- printf("%lld\n",pow(pow(,k)-,n));
- }
ZOJ 3556 How Many Sets I的更多相关文章
- [容斥原理] zoj 3556 How Many Sets I
主题链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4535 How Many Sets I Time Limit: 2 ...
- zoj——3556 How Many Sets I
How Many Sets I Time Limit: 2 Seconds Memory Limit: 65536 KB Give a set S, |S| = n, then how ma ...
- zoj 3557 How Many Sets II
How Many Sets II Time Limit: 2 Seconds Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...
- zoj——3557 How Many Sets II
How Many Sets II Time Limit: 2 Seconds Memory Limit: 65536 KB Given a set S = {1, 2, ..., n}, n ...
- ZOJ 3556
终于做出来了,激动.... 这道题隐藏得深啊,但若推导下来,就变简单了. 首先,一个集合的子集的个数为2^n=s.注意了,题目求的是有序集合组,并且每个集合是可以重复使用的,怎么办呢?这就要想到多重集 ...
- How Many Sets I(容斥定理)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3556 How Many Sets I Time Limit: 2 ...
- 组合数们&&错排&&容斥原理
最近做了不少的组合数的题这里简单总结一下下 1.n,m很大p很小 且p为素数p要1e7以下的 可以接受On的时间和空间然后预处理阶乘 Lucas定理来做以下是代码 /*Hdu3037 Saving B ...
- zoj How Many Sets I(组合计数)
http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4535 一个集合s有n个元素,求满足这种集合序列{s1,s2....sk}使S ...
- ZOJ 1586 QS Network (最小生成树)
QS Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...
随机推荐
- Document对象内容集合
document 文挡对象 - JavaScript脚本语言描述———————————————————————注:页面上元素name属性和JavaScript引用的名称必须一致包括大小写否则会提示你一 ...
- 三:Fair Scheduler 公平调度器
参考资料: http://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/FairScheduler.html http://h ...
- C Program进阶-数组
(一)数组的内存布局 对于语句int a[5]; 我们明白这里定义了一个数组,数组里有5个元素,每一个元素都是int类型,我们可以用a[0],a[1]等访问数组里的元素,但是这些元素的名字就是a[0] ...
- lintcode-42-最大子数组 II
42-最大子数组 II 给定一个整数数组,找出两个 不重叠 子数组使得它们的和最大. 每个子数组的数字在数组中的位置应该是连续的. 返回最大的和. 注意事项 子数组最少包含一个数 样例 给出数组 [1 ...
- LintCode-72.中序遍历和后序遍历树构造二叉树
中序遍历和后序遍历树构造二叉树 根据中序遍历和后序遍历树构造二叉树 注意事项 你可以假设树中不存在相同数值的节点 样例 给出树的中序遍历: [1,2,3] 和后序遍历: [1,3,2] 返回如下的树: ...
- Debian 7 amd64--TP-LINK TL-WN725N 2.0源码驱动编译安装
租房用的是无线网络,在新安装的Debian 7 amd64使用的无线网卡型号是TP-LINK TL-WN725N 2.0,发现驱动安装还是有些问题,折腾了很久,特意在此记录一下. TL-WN725N ...
- week1技术随笔
2016-09-06 2016年9月3日 类别c 内容c 开始时间s 结束时间e 被打断时间I 总计(min) 读书 读构建之法 8:40 10:00 11 69 读书 构建之法-个人能力 , ...
- C# 使用this的形参
示例1: public static RectangleF TransformRect(this Matrix mat, RectangleF rect) 是向Matrix类扩展带有Rectangle ...
- 特殊符号存入mysql数据库时报错:Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F的解决方法
问题描述:从新浪微博抓取消息保存到MySQL数据中,对应数据库字段为varchar,字符编码utf-8.部分插入成功,部分插入失败,报错如标题. 在网上查询,有人说是编码问题,建议修改编码格式,比如改 ...
- SpringBoot2.0(一) mybatis
使用mybatis springboot使用mybatis主要依赖 mybatis-spring-boot-starter 来实现.其提供了2中解决方案,一种是使用注解:另一种是简化后的传统的xml方 ...