描述

In order to celebrate the 8th anniversary of ZOJ, LCLL goes to a sauce factory to "Get Sauce". The factory has N kinds of materials. If we combine some of them, we will get a bottle of sauce. LCLL is a sauce genius, he knows about M ways to make the sauce with these materials. Now LCLL wants to get as many bottles of sauce as possible, but he can use each kind of material only once. How many bottles of sauce will LCLL take home at most?

输入

The input file will contain multiple test cases. Each case contains two integers N and M(0 <=N <= 16, 0<= M <=50,000), then there are M lines, each line describe a way to make sauce like this: K a1,a2...aK where K(1<=K<=N) is the number of kinds of materials, ai is a number between[1,N] represents a kind of material this way needs.

Process to the end-of-file.

输出

For each test case print a single line that contains the number of the bottles of sauce LCLL will get at most.

样例输入

5 3
2 1 2
2 2 3
2 3 4

5 2
1 1
4 1 2 3 4

样例输出

2
1

题目大意:

现在有n种材料(每种只有一个),m种方案,每种方案需要若干种材料,求最多能 完成的方案数。

#include <bits/stdc++.h>
using namespace std;
int dp[<<];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(dp,,sizeof dp);
int S=(<<n)-;
for(int i=,k;i<=m;i++)
{
scanf("%d",&k);
int s=;
for(int j=,x;j<=k;j++)
scanf("%d",&x),s|=(<<(x-));
int res=S^s;
dp[s]=max(dp[s],);
for(int j=res;j;j=(j-)&res)///遍历res子集
if(dp[j])
dp[s|j]=max(dp[s|j],dp[j]+);
}
int ans=;
for(int i=;i<=S;i++)
ans=max(ans,dp[i]);
printf("%d\n",ans);
}
return ;
}

Get Sauce(状压DP)的更多相关文章

  1. BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]

    1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3336  Solved: 1936[Submit][ ...

  2. nefu1109 游戏争霸赛(状压dp)

    题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...

  3. poj3311 TSP经典状压dp(Traveling Saleman Problem)

    题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...

  4. [NOIP2016]愤怒的小鸟 D2 T3 状压DP

    [NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...

  5. 【BZOJ2073】[POI2004]PRZ 状压DP

    [BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...

  6. bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)

    数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...

  7. HDU 1074 Doing Homework (状压dp)

    题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...

  8. 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP

    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...

  9. 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP

    [BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...

  10. 【BZOJ1087】 [SCOI2005]互不侵犯King 状压DP

    经典状压DP. f[i][j][k]=sum(f[i-1][j-cnt[k]][k]); cnt[i]放置情况为i时的国王数量 前I行放置情况为k时国王数量为J #include <iostre ...

随机推荐

  1. iPad开发简单介绍

    iPad开发最大的不同在于iPhone的就是屏幕控件的适配,以及横竖屏的旋转. Storyboard中得SizeClass的横竖屏配置,也不支持iPad开发. 1.在控制器中得到设备的旋转方向 在 i ...

  2. [转载]—Health Check Reports Problem: Dependency$ p_timestamp mismatch for VALID objects (文档 ID 781959.1)

    Health Check Reports Problem: Dependency$ p_timestamp mismatch for VALID objects (文档 ID 781959.1) AP ...

  3. 如何修改Ruby的gem源(gem sources)

    Ruby环境下的gem sources地址默认是国外网络地址,所以在使用gem的过程中经常会出现找不到资源的Error.那么如何解决这种Error?方法很简单:要么就多次尝试执行gem命令,要么就修改 ...

  4. mysql-新增、更新、删除语句

    1.插入数据: INSERT INTO t_book VALUES(NULL,'我爱我家',20,'张三',1); INSERT INTO t_book(id,bookName,price,autho ...

  5. 安装新版REDIS

    http://redis.io/ # wget http://download.redis.io/redis-stable.tar.gz tar zxvf redis-stable.tar.gz -C ...

  6. Ubuntu18.04偏好设置

    以下只是我个人的一些偏好设置,会持续更新 一.安装中文输入法和换用中文界面 Ubuntu18.04下安装搜狗输入法 Ubuntu18.04如何从英文界面更改为中文界面 二.更改系统自带设置 1.设置- ...

  7. 《大规模 web服务开发》笔记

    大规模服务:     可扩展,负载均衡,保证冗余,低运维成本,开发人数和开发方法的变化 数据处理:     磁盘—>内存—>缓存—>CPU 障碍:     持续增长的服务,”无法在内 ...

  8. 厌食?暴食?试试这个 VR 新疗法

    今日导读 “我知道我要吃饭,但我真的什么都吃不下.” “我脑子里想的只有吃东西,吃吃吃!” ....... 作为一个正常人,我们完全无法想象患厌食症或贪食症人群所受的痛苦.长期的厌食,会使一个人瘦的只 ...

  9. 【转】JavaScript 节点操作 以及DOMDocument属性和方法

    最近发现DOMDocument对象很重要,还有XMLHTTP也很重要 注意大小写一定不能弄错. 属性: 1Attributes 存储节点的属性列表(只读) 2childNodes 存储节点的子节点列表 ...

  10. sql 经典加强巩固练习题

    由于本人需要加强巩固一下数据库知识,就搜罗了一些题目来练习,感觉不错,故分享一下资源难度层度依次上升这50道里面自认为应该没有太多错误,而且尽可能使用了最简单或是最直接的查询,有多种不相上下解法的题目 ...