程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu 3006 The Number of set(思維+壯壓DP)

hdu 3006 The Number of set(思維+壯壓DP)

編輯:C++入門知識

The Number of set

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


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 2009 Multi-University Training Contest 11 - Host by HRBEU
Recommend gaojie | We have carefully selected several similar problems for you: 3007 3003 3004 3002 3005

題意:

給你n個集合。集合中均為數字且數字的范圍在[1,m]內。m<=14。現在問用這些集合能組成多少個集合自己本身也算。

思路:

開始有點無頭緒。一看到m范圍就樂了。正好用二進制壓縮。第i為1表示集合裡有i這個數。然後背包就行了。

詳細見代碼:

#include
#include
#include
using namespace std;

const int maxn=100010;
//typedef __int64 ll;
int dp[1<<15],s[110],base[15];
int main()
{
    int n,m,i,j,k,tp,ans;

    base[0]=1;
    for(i=1;i<=15;i++)
        base[i]=base[i-1]<<1;
    while(~scanf("%d%d",&n,&m))
    {
        memset(dp,0,sizeof dp);
        dp[0]=1,ans=0;
        for(i=0;i=0;j--)
                if(dp[j])
                    dp[j|s[i]]=1;
        for(i=base[m]-1;i>=1;i--)
            if(dp[i])
                ans++;
        printf("%d\n",ans);
    }
    return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved