zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    学习记录6
    学习记录5
    学习记录4
    学习记录3&开启新的世界
    学习记录2
    学习记录1
    类、对象和包
    班会总结
    请简单描述一下,java程序的运行过程,以及java为什么能跨平台
    JDK、JRE、JVM的区别与关系
  • 原文地址:https://www.cnblogs.com/fraud/p/4733488.html
Copyright © 2011-2022 走看看