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

(状态压缩DP) hdu 3006

时间:2015-04-17 13:15:15      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

I - The Number of set
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Appoint description: 

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
 
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
int n,m,dp[(1<<14)+10];
int main()
{
    int x,temp;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int ans=0;
        memset(dp,0,sizeof(dp));
        while(n--)
        {
            scanf("%d",&x);
            int ret=0;
            for(int i=1;i<=x;i++)
            {
                scanf("%d",&temp);
                ret=ret|(1<<(temp-1));
            }
            dp[ret]=1;
            for(int i=0;i<(1<<m);i++)
            {
                if(dp[i])
                    dp[(ret|i)]=1;
            }
        }
        for(int i=0;i<(1<<m);i++)
            if(dp[i])
                ans++;
        printf("%d\n",ans);
    }
    return 0;
}

  

(状态压缩DP) hdu 3006

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4434242.html

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