Get Sauce(状压DP)
描述
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)的更多相关文章
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- nefu1109 游戏争霸赛(状压dp)
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...
- poj3311 TSP经典状压dp(Traveling Saleman Problem)
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
- [NOIP2016]愤怒的小鸟 D2 T3 状压DP
[NOIP2016]愤怒的小鸟 D2 T3 Description Kiana最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于(0,0)处,每次Kiana可 ...
- 【BZOJ2073】[POI2004]PRZ 状压DP
[BZOJ2073][POI2004]PRZ Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍 ...
- bzoj3380: [Usaco2004 Open]Cave Cows 1 洞穴里的牛之一(spfa+状压DP)
数据最多14个有宝藏的地方,所以可以想到用状压dp 可以先预处理出每个i到j的路径中最小权值的最大值dis[i][j] 本来想用Floyd写,无奈太弱调不出来..后来改用spfa 然后进行dp,这基本 ...
- HDU 1074 Doing Homework (状压dp)
题意:给你N(<=15)个作业,每个作业有最晚提交时间与需要做的时间,每次只能做一个作业,每个作业超出最晚提交时间一天扣一分 求出扣的最小分数,并输出做作业的顺序.如果有多个最小分数一样的话,则 ...
- 【BZOJ1688】[Usaco2005 Open]Disease Manangement 疾病管理 状压DP
[BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) ...
- 【BZOJ1725】[Usaco2006 Nov]Corn Fields牧场的安排 状压DP
[BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排 Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行(1<=M< ...
- 【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 ...
随机推荐
- django之基于cookie和装饰器实现用户认证
示例1 # Create your views here. user = "a" pwd = "a" def login(request): if reques ...
- CentOS6.4安装JDK,卸载自带的OpenJDK
1.查看OpenJDK的安装包 $ rpm -qa |grep java java-1.6.0-openjdk-1.6.0.0-1.62.1.11.11.90.el6_4.x86_64 java-1. ...
- 如何修改Ruby的gem源(gem sources)
Ruby环境下的gem sources地址默认是国外网络地址,所以在使用gem的过程中经常会出现找不到资源的Error.那么如何解决这种Error?方法很简单:要么就多次尝试执行gem命令,要么就修改 ...
- HDU 5500 Reorder the Books (水题)
题意: 有n本书,编号为1~n,现在书的顺序乱了,要求恢复成有序的样子,每次只能抽出其中一本并插到最前面,问最少需要多少抽几次? 思路: 如果pos[i]放的不是书i的话,则书i的右边所有的书都必须抽 ...
- 关于JavaScript的变量和函数提升
第一种理解方式:let和const不能被使用,直到他们被声明 对于var定义的变量,解析器会提升其到作用域顶部. // Outputs: undefined console.log(x); var x ...
- 日常-acm-开灯问题
开灯问题.有n盏灯,编号1-n.第一个人把所有的灯打开,第二个人按下所有编号为二的倍数的开关(全关掉),第三个人按下所有编号为三的倍数的开关,以此类推.一共k个人,问最后开着的灯的编号.输入n和k,输 ...
- Python-OpenCV中的cv2.inpaint()函数
概念 修复是图像插值.数字修复算法在图像插值,照片恢复,缩放和超分辨率等方面具有广泛的应用. 大多数人会在家里放一些旧的退化照片,上面有一些黑点,一些笔画等.你有没有想过恢复它?我们不能简单地在绘画工 ...
- 1003: Redraiment的遭遇
1003: Redraiment的遭遇 Time Limit: 1000 Sec Memory Limit: 128 MBSubmit: 456 Solved: 158[Submit][Statu ...
- CPP-网络/通信:经典HTTP协议详解
2008-11-03 09:11 by Hundre, 266688 阅读, 23 评论, 收藏, 编辑 转自:http://blog.csdn.net/gueter/archive/2007/03/ ...
- ES6中const的用法
const声明一个只读的常量.一旦声明,常量的值就不能改变.且const一旦声明变量,就必须立即初始化,不能留到以后赋值. const的作用域与let命令相同:只在声明所在的块级作用域内有效. con ...