The Number of set

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 722    Accepted Submission(s): 437


Problem Description
Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use these sets to combinate the new set,how many different new set you can get.The given sets can not be broken.
 

 

Input
There are several cases.For each case,the first line contains two positive integer n and m(1<=n<=100,1<=m<=14).Then the following n lines describe the n sets.These lines each contains k+1 positive integer,the first which is k,then k integers are given. The input is end by EOF.
 

 

Output
For each case,the output contain only one integer,the number of the different sets you get.
 

 

Sample Input
4 4 1 1 1 2 1 3 1 4 2 4 3 1 2 3 4 1 2 3 4
 

 

Sample Output
15 2
 

 

Source
 

 

Recommend
gaojie

//这题很神奇的算法、呵呵

#include <iostream>
#include <stdio.h>
#include <string.h>
#define Y 1<<15
using namespace std;
bool a[Y+1];
int main()
{
    int n,m,in;
    int i,k,t,tin;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        t=1<<(m+1);
        for(i=1;i<=t;i++)
          a[i]=0;
        for(i=1;i<=n;i++)
        {
           scanf("%d",&k);
           tin=0;
           while(k--)
           {
             scanf("%d",&in);
             tin+=1<<in;
           }
           a[tin]=1;
          for(k=1;k<=t;k++)
            if(a[k])
             a[k|tin]=1;
        }
        k=0;
      for(i=1;i<=t;i++)
          if(a[i])
           k++;
      printf("%d\n",k);
    }
    return 0;
}