zoukankan      html  css  js  c++  java
  • ZOJ 3556 How Many Sets I

    How Many Sets I

    Time Limit: 2000ms
    Memory Limit: 65536KB
    This problem will be judged on ZJU. Original ID: 3556
    64-bit integer IO format: %lld      Java class name: Main
     

    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

    Source

    Author

    QU, Zhe
     
    解题:

    从子集中选k个的有序组合个数(子集可重复被选中)有 $(2^n)^k=2^{n imes k}$;

     故总数为$S=2^{n imes k}$;

     $设S(x)为k个集合的有序组合的个数,这些集合都包含至少一个x。$

     $S(x_1 & x_2)为k个集合的有序组合的个数,这些集合都包含至少一个x_1和x_2$

     $S(x_1& x_2& x_3...x_k)为k个集合的有序组合的个数,这些集合都包含至少一个x_1,x_2...x_k。$

     $而  S(x)=(2^{n-1})^k =2^{(n-1) imes k};$

     $S(x_1 & x_2)=(2^{n-2})^k=2^{(n-2) imes k};$

     $S(x_1& x_2 &...& x_i)=(2^{n-i})^k=2^{(n-i) imes k};$

     由容斥原理知,我们要得到的就是

    $S-(n,1) imes S(x) + (n,2) imes (S(x_1& x_2)-(n,3) imes (S(x_1& x_2&x_3)+....(-1)^i imes (n,i) imes S(x_1& x_2&...x_i)...(-1)^n imes (n,n) imes S(x_1& x_2...& x_n);$

    $化简得ans=(2^K-1)^N;$

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 LL mod = 1000000007,n,k;
     5 LL quickPow(LL base,LL index){
     6     LL ret = 1;
     7     while(index){
     8         if(index&1) ret = ret*base%mod;
     9         index >>= 1;
    10         base = base*base%mod;
    11     }
    12     return ret;
    13 }
    14 int main(){
    15     while(~scanf("%lld%lld",&n,&k))
    16         printf("%lld
    ",quickPow(((quickPow(2,k) - 1)%mod + mod)%mod,n));
    17     return 0;
    18 }
    View Code
  • 相关阅读:
    union 和 union all的区别
    JDBC中PreparedStatement相比Statement的好处
    25个经典的Spring面试问答
    MySQL 事务
    漫谈Linux下的音频问题(转)
    监控 Linux 性能的 18 个命令行工具(转)
    在终端中用默认程序打开文件(转)
    【转】使程序在Linux下后台运行 (关掉终端继续让程序运行的方法)
    Getting Started with Amazon EC2 (1 year free AWS VPS web hosting)
    压缩解压命令小结
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4850923.html
Copyright © 2011-2022 走看看