码迷,mamicode.com
首页 > 其他好文 > 详细

TOJ4505: KOSARE

时间:2017-12-19 01:01:11      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:sea   空间   ref   simple   contains   panel   forum   only   lin   

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

标签:sea   空间   ref   simple   contains   panel   forum   only   lin   

原文地址:http://www.cnblogs.com/BobHuang/p/8059974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!