zoj How Many Sets I(组合计数)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4535

一个集合s有n个元素,求满足这样的集合序列{s1,s2....sk}使S1 ∩
S2 ∩ ... ∩ Sk =
?,si是s的子集。

从每个元素考虑会使问题变得简单。首先n个元素是相互独立的,单独考虑第i个元素,它在k个子集的所有情况是2^k,其中有一种情况是k个子集都有第i个元素,这一种情况正好不是我们想要的,所以合法的应该是2^k-1,那么n个元素就是( 2^k-1 )^n。

#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <list>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
//#define LL __int64
#define LL long long
#define ULL unsigned long long
#define eps 1e-9
#define PI acos(-1.0)
using namespace std;

const LL mod = 1000000007;

LL Pow(LL a, LL b)
{
    LL res = 1;
    while(b)
    {
        if(b&1)
            res = (res*a)%mod;
        b >>= 1;
        a = (a*a)%mod;
    }
    return res;
}

int main()
{
    LL n,k;
    while(~scanf("%lld %lld",&n,&k))
    {
        LL res = Pow((LL)2,k);
        res -= 1;
        res = Pow(res,n);
        printf("%lld\n",res);
    }
    return 0;
}
时间: 2024-11-04 13:49:42

zoj How Many Sets I(组合计数)的相关文章

ZOJ 3791 An Easy Game [组合计数]

题目地址: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3791 题目描述: 给定两个长度为n的01串s1,s2,要求用k步,每一步反转s1的m个位置的数码(即0变为1,1变为0),问能有多少种做法,在k步之后将s1变成s2. 1 <= n <= 100, 0 <= k <= 100, 0 <= m <= n. 解题思路: 典型的组合计数问题. 首先比较s1和s2,记s1和s2数码不同的位置有

Yue Fei&#39;s Battle(组合计数递推)

//求一个直径为 k 的树有多少种形态,每个点的度不超过 3 // 非常完美的分析,学到了,就是要细细推,并且写的时候要细心 还有除法取模需要用逆元 #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> using namespace std; #define MOD 1000000007 #define L

POJ 1496 POJ 1850 组合计数

Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Transmitting and memorizing information is a task that requires different coding systems for the best use of the available space. A well known system is t

bzoj 1004 Cards 组合计数

这道题考察的是组合计数(用Burnside,当然也可以认为是Polya的变形,毕竟Polya是Burnside推导出来的). 这一类问题的本质是计算置换群(A,P)中不动点个数!(所谓不动点,是一个二元组(a,p),a∈A,p∈P ,使得p(a)=a,即a在置换p的作用后还是a). Polya定理其实就是告诉了我们一类问题的不动点数的计算方法. 对于Burnside定理的考察,我见过的有以下几种形式(但归根结底还是计算不动点数): 1.限制a(a∈A)的特点,本题即是如此(限制了各颜色个数,可以

POJ 3252 组合计数

Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9149 Accepted: 3248 Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro,

HDU4675-GCD of Sequence(数论+组合计数)

GCD of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 949    Accepted Submission(s): 284 Problem Description Alice is playing a game with Bob. Alice shows N integers a1, a2, -, aN, an

[HDU 3461] Saving Beans &amp; 组合计数Lucas定理模板

Saving Beans Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold

POJ 1019 组合计数

链接:POJ 1019 /***************************************** author : Grant Yuan time : 2014/10/19 14:38 source : POJ 1019 algorithm: 组合计数 ******************************************/ #include <iostream> #include <cstdio> #include <algorithm> #

HDU 4832 组合计数dp

Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 509    Accepted Submission(s): 198 Problem Description 小度和小良最近又迷上了下棋.棋盘一共有N行M列,我们可以把左上角的格子定为(1,1),右下角的格子定为(N,M).在他们的规则中,"王"在棋盘上的走法遵循十字