ZOJ3556 How Many Sets I(容斥)
2015-08-16 01:05
459 查看
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
How Many Sets ITime 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))
容斥推一下公式,大致就是有一个相交,两个相交。。。。。。
最后可以推出公式是((2^k)-1)^n,还是比较容易得出公式的
How Many Sets ITime 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
容斥推一下公式,大致就是有一个相交,两个相交。。。。。。
最后可以推出公式是((2^k)-1)^n,还是比较容易得出公式的
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author xyiyy @https://github.com/xyiyy */ #include <iostream> #include <fstream> //##################### //Author:fraud //Blog: http://www.cnblogs.com/fraud/ //##################### //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <sstream> #include <ios> #include <iomanip> #include <functional> #include <algorithm> #include <vector> #include <string> #include <list> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <climits> #include <cctype> using namespace std; typedef long long ll; const ll MOD = 1000000007; // // Created by xyiyy on 2015/8/5. // #ifndef ICPC_QUICK_POWER_HPP #define ICPC_QUICK_POWER_HPP typedef long long ll; ll quick_power(ll n, ll m, ll mod) { ll ret = 1; while (m) { if (m & 1) ret = ret * n % mod; n = n * n % mod; m >>= 1; } return ret; } #endif //ICPC_QUICK_POWER_HPP class TaskH { public: void solve(std::istream &in, std::ostream &out) { int n, k; while (in >> n >> k) { ll ans = quick_power(2, k, MOD) - 1; ans = (ans + MOD) % MOD; ans = quick_power(ans, n, MOD); out << ans << endl; } } }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); TaskH solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
相关文章推荐
- POJ 2886 Who Gets the Most Candies? (线段树 约瑟夫环问题变种)
- 我是季重生
- 算法题:前缀表达式的运算
- 1.Two Sum
- Unity Shader 学习笔记 (四) Pass里可用的渲染没置命令
- SDWebImageInfo
- codeforces 314 D One-Dimensional Battle Ships (模拟)
- 算法高手
- android studio使用心得
- ZOJ3555 Ice Climber(dp)
- BZOJ2933 : [Poi1999]地图
- url防注入
- 前端笔记
- iOS概念入门学习-OC-@property关键字
- [置顶] android studio导入项目后出现cannot resolve symbol r android studio错误
- 点歌系统(使用TreeSet)
- 恢复回收站删除的文件
- runloop
- [C语言][LeetCode][228]Summary Ranges
- LeetCode Search a 2D Matrix II