ZOJ3556 How Many Sets I(容斥)

转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

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

容斥推一下公式,大致就是有一个相交,两个相交。。。。。。

最后可以推出公式是((2^k)-1)^n,还是比较容易得出公式的

 1 /**
 2  * code generated by JHelper
 3  * More info: https://github.com/AlexeyDmitriev/JHelper
 4  * @author xyiyy @https://github.com/xyiyy
 5  */
 6 
 7 #include <iostream>
 8 #include <fstream>
 9 
10 //#####################
11 //Author:fraud
12 //Blog: http://www.cnblogs.com/fraud/
13 //#####################
14 //#pragma comment(linker, "/STACK:102400000,102400000")
15 #include <iostream>
16 #include <sstream>
17 #include <ios>
18 #include <iomanip>
19 #include <functional>
20 #include <algorithm>
21 #include <vector>
22 #include <string>
23 #include <list>
24 #include <queue>
25 #include <deque>
26 #include <stack>
27 #include <set>
28 #include <map>
29 #include <cstdio>
30 #include <cstdlib>
31 #include <cmath>
32 #include <cstring>
33 #include <climits>
34 #include <cctype>
35 
36 using namespace std;
37 typedef long long ll;
38 
39 const ll MOD = 1000000007;
40 
41 //
42 // Created by xyiyy on 2015/8/5.
43 //
44 
45 #ifndef ICPC_QUICK_POWER_HPP
46 #define ICPC_QUICK_POWER_HPP
47 typedef long long ll;
48 
49 ll quick_power(ll n, ll m, ll mod) {
50     ll ret = 1;
51     while (m) {
52         if (m & 1) ret = ret * n % mod;
53         n = n * n % mod;
54         m >>= 1;
55     }
56     return ret;
57 }
58 
59 #endif //ICPC_QUICK_POWER_HPP
60 
61 class TaskH {
62 public:
63     void solve(std::istream &in, std::ostream &out) {
64         int n, k;
65         while (in >> n >> k) {
66             ll ans = quick_power(2, k, MOD) - 1;
67             ans = (ans + MOD) % MOD;
68             ans = quick_power(ans, n, MOD);
69             out << ans << endl;
70         }
71     }
72 };
73 
74 int main() {
75     std::ios::sync_with_stdio(false);
76     std::cin.tie(0);
77     TaskH solver;
78     std::istream &in(std::cin);
79     std::ostream &out(std::cout);
80     solver.solve(in, out);
81     return 0;
82 }

 

转载于:https://www.cnblogs.com/fraud/p/4733488.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值