 /**//*
題意:n種材料,m種方案,每種方案會(huì)選擇一些物品做出產(chǎn)品,問(wèn)最多能
做出多少種產(chǎn)品,但材料只能使用一次

比較特別的01背包
看二進(jìn)制位,就是背包容量了 , 方案會(huì)占據(jù)一些位(或者說(shuō)容量)
用01背包更新即可
這里二進(jìn)制枚舉補(bǔ)集的子集

不是很快 600ms
方案很多重復(fù)、包含
可以先去重,還有去掉一些包含的,然后會(huì)快很多 , 200多ms吧
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#include<cstdlib>
#include<iostream>

using namespace std;

const int INF = 1000000000;
const int MAXN = 10010;

int dp[1<<16];

int main()
  {

#ifdef ONLINE_JUDGE
#else
freopen("in", "r", stdin);
#endif

int n , m;
while( ~scanf("%d%d",&n,&m) )
 {
int limit = (1<<n);
fill(dp,dp+limit,0);
for(int i = 0 ; i < m ; i++)
 {
scanf("%d",&n);
if(n==0)continue;//
int mask = 0 , x;
for(int j = 0 ; j < n ; j++)
 {
scanf("%d",&x);
mask |= (1<<x-1);
}
dp[mask] = max(dp[mask] , 1);
int _mask = mask ^ (limit-1);//補(bǔ)集
for(int j = _mask ; j ; j = (j-1) & _mask)
 {
dp[mask | j] = max(dp[mask | j] , dp[j] + 1);
}
}
printf("%d\n" , *max_element(dp,dp+limit) );
}
return 0;
}


|
|
常用鏈接
隨筆分類(lèi)
Links
搜索
最新評(píng)論

|
|