How Many Sets I
来源:互联网 发布:古筝曲谱制作软件 编辑:程序博客网 时间:2024/05/09 11:20
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 12 2
Sample Output
19
个数为n的集合的子集有2^n个,从中选出K个使得他们的交集为空的个数。
由于集合可以重复被选,所以总的数目是2^(kn)
然后选中的集合都包含x这个数的数目是c(n,1)*2^(n-1)k
选中的集合包含x1,x2的数目是c(n,2)*2^(n-2)k
……
所以满足的集合的个数res=2^kn-c(n,1)*2^(n-1)k+c(n,2)*2(n-2)k-……
推出的公式为(2^k-1)^n
- #include<iostream>
- #include<cstdlib>
- #include<stdio.h>
- using namespace std;
- #define mm 1000000007
- typedef long long ll;
- ll powermod(ll a,ll b)
- {
- ll res=1;
- while(b)
- {
- if(b&1)res=(res*a)%mm;//不能写成res*=a%mm~~~~~~~~~
- a=a*a;
- a%=mm;
- b>>=1;
- }
- return res%mm;
- }
- int main()
- {
- ll n,k;
- while(scanf("%lld%lld",&n,&k)!=EOF)
- {
- ll ans=powermod(2,k);
- ans--;
- ans=powermod(ans,n);
- printf("%lld\n",ans);
- }
- }
0 0
- How Many Sets I
- How Many Sets I
- zoj3556 How Many Sets I-------容斥
- zoj How Many Sets I(组合计数)
- How Many Sets
- How Many Sets
- ZOJ 3556 How Many Sets I 解题报告(数论)
- [容斥原理] zoj 3556 How Many Sets I
- ZOJ 3556 How Many Sets I 二项式+容斥
- ZOJ 3556 How Many Sets I (容斥)
- ZOJ3556 How Many Sets I【容斥原理】
- zoj 3556 How Many Sets I - 容斥原理
- zoj 3556 How Many Sets I(容斥原理)
- Sicily 4428. How Many Sets
- Sicily 4428 How Many Sets
- zoj How Many Sets I 3556 (容斥原理&&规律)
- [2014Contest_1I]How Many Sets II
- ZOJ 3557 How Many Sets II
- 于敦德:途牛五大战略纵深不惧同质化竞争
- js中substring和substr的用法
- 一起talk C栗子吧(第二十六回:C语言实例--冒泡排序)
- KNIMI数据挖掘建模与分析系列_004_利用KNIMI做客户流失预测
- iOS UI03_UIViewController视图控制器
- How Many Sets I
- Android动画总结
- 安全驾驶-座椅枕头高度(九)
- div重叠和隐藏显示
- 把View和TextField进行封装
- 安全驾驶-预防爆胎(十)
- [leetcode 32]Longest Valid Parentheses
- IP地址的规划和设计方法(二)
- Android如何获取选择图片时的文件绝对路径方法