TOJ4505: KOSARE

Posted BobHuang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TOJ4505: KOSARE相关的知识,希望对你有一定的参考价值。

TOJ4505: KOSARE 技术分享图片

Time Limit(Common/Java):10000MS/30000MS     Memory Limit:65536KByte
Total Submit: 11            Accepted:3

Description

 

Mirko found N boxes with various forgotten toys at his attic. There are M different toys, numbered 1 through M, but each of those can appear multiple times across various boxes.
Mirko decided that he will choose some boxes in a way that there is at least one toy of each kind present, and throw the rest of the boxes away.
Determine the number of ways in which Mirko can do this.

 

Input

 

The first line of input contains two integers N and M (1 ≤ N ≤ 1 000 000, 1 ≤ M ≤ 20).
Each of the following N lines contains an integer Ki (0 ≤ Ki ≤ M) followed by Ki distinct integers from interval [1, M], representing the toys in that box.

 

Output

 

The first and only line of output should contain the requested number of ways modulo 1 000 000 007.

 

Sample Input

3 3
3 1 2 3
3 1 2 3
3 1 2 3

Sample Output

 7

Source

COCI 2011/2012 Contest #6

 

#include<stdio.h>
const int N=1<<20,MD=1e9+7;
int cnt[N],B[N],n,m,ans[N],f;
int main()
{
    scanf("%d%d",&n,&m);
    f=1<<m;
    B[0]=1;
    for(int i=1; i<=n; i++)
        B[i]=(B[i-1]<<1)%MD;
    for(int i=0,t,x,s; i<n; i++)
    {
        scanf("%d",&t);
        s=0;
        while(t--)
            scanf("%d",&x),s|=1<<x-1;
        cnt[s]++;
    }
    for(int i=0; i<m; i++)
        for(int s=0; s<f; s++)
            if(s&1<<i)
                cnt[s]+=cnt[s^1<<i];
    for(int s=0; s<f; s++)
        ans[s]=B[cnt[s]];
    for(int i=0; i<m; i++)
        for(int s=0; s<f; s++)
            if(s&1<<i)
                ans[s]=(ans[s]-ans[s^1<<i]+MD)%MD;
    printf("%d",ans[f-1]);
    return 0;
}

 

 

 

 








以上是关于TOJ4505: KOSARE的主要内容,如果未能解决你的问题,请参考以下文章

TOJ1290 Poker Hands 模拟题

SYN4505型 标准同步时钟

英特尔赛扬 N4505怎么样 相当于什么水平

CVE-2019-4505: WebSphere 任意文件读取漏洞预警

C++:当包含从类模板派生的类的标头时,编译器警告 C4505

TOJ礼品兑换 (多重背包恰好装满)