描述

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. ionic 2 起航 控件的使用 客户列表场景(四)

    接下来,我们的客户列表要怎么刷新数据呢? 我们不会安卓开发,不会ios开发,没关系,我们还有ionic 2.ionic 2的控件 Ion-refresher 轻松帮我们搞掂. <!--下拉刷新- ...

  2. 利用任务计划自动删除指定日期的SQLServer备份文件

    利用任务计划自动删除指定日期的SQLServer备份文件 命令FORFILES [/P pathname] [/M searchmask] [/S]         [/C command] [/D ...

  3. LR脚本示例之参数_变量介绍

    Action(){ char *url = "127.0.0.1:1080"; char arr_url[1024]; //将url变量的值复制给p_url1参数 lr_save_ ...

  4. 洛谷 P2827 蚯蚓

    题目描述 本题中,我们将用符号\lfloor c \rfloor⌊c⌋表示对c向下取整,例如:\lfloor 3.0 \rfloor= \lfloor 3.1 \rfloor=\lfloor 3.9 ...

  5. 重温Javascript(二)-对象

    对象 可以想象成散列表,键值对,值可以是数据或函数 创建对象的方式 1.工厂模式 function createPerson(name, age, job){ var o = new Object() ...

  6. spring aop切面中获取代理bean的名字以及bean

    //切面中搞: Map<String , Object> map = (Map)ApplicationContextHelper.getBean(proceedingJoinPoint.g ...

  7. javaweb基础(22)_Servlet+JSP+JavaBean实战登陆

    一.Servlet+JSP+JavaBean开发模式(MVC)介绍 Servlet+JSP+JavaBean模式(MVC)适合开发复杂的web应用,在这种模式下,servlet负责处理用户请求,jsp ...

  8. Spring源码剖析依赖注入实现

    Spring源码剖析——依赖注入实现原理 2016年08月06日 09:35:00 阅读数:31760 标签: spring源码bean依赖注入 更多 个人分类: Java   版权声明:本文为博主原 ...

  9. 常用的windows小工具指令和如何打开自定义的程序

    windows可以通过 开始->运行->输入程序名 或 windows键+R键 两种方式来启动windows中自带的程序或手动安装的程序.下面介绍一些常用的windows工具的指令和如何打 ...

  10. laravel中使用PHPQuery实现网页采集

    由于没有PHPQuery的composer包安装所以需要我们手动在我们的laravel项目中安装加载PHPQuery,这里需要设置laravel的autoload->class map. 1.首 ...