您的位置:首页 > 其它

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))

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: