Hamburger Magi

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

Problem Description
In the mysterious forest, there is a group of Magi. Most of them like to eat human beings, so they are called “The Ogre Magi”, but there is an special one whose favorite food is hamburger, having been jeered by the others as “The Hamburger Magi”.
Let’s give The Hamburger Magi a nickname “HamMagi”, HamMagi don’t only love to eat but also to make hamburgers, he makes N hamburgers, and he gives these each hamburger a value as Vi, and each will cost him Ei energy, (He can use in total M energy each day). In addition, some hamburgers can’t be made directly, for example, HamMagi can make a “Big Mac” only if “New Orleams roasted burger combo” and “Mexican twister combo” are all already made. Of course, he will only make each kind of hamburger once within a single day. Now he wants to know the maximal total value he can get after the whole day’s hard work, but he is too tired so this is your task now!
 
Input
The first line consists of an integer C(C<=50), indicating the number of test cases.
The first line of each case consists of two integers N,E(1<=N<=15,0<=E<=100) , indicating there are N kinds of hamburgers can be made and the initial energy he has.
The second line of each case contains N integers V1,V2…VN, (Vi<=1000)indicating the value of each kind of hamburger.
The third line of each case contains N integers E1,E2…EN, (Ei<=100)indicating the energy each kind of hamburger cost.
Then N lines follow, each line starts with an integer Qi, then Qi integers follow, indicating the hamburgers that making ith hamburger needs.
 
Output
For each line, output an integer indicating the maximum total value HamMagi can get.
 
Sample Input
1
4 90
243 464 307 298
79 58 0 72
3 2 3 4
2 1 4
1 1
0
 
Sample Output
298
 
做的第二道状态压缩dp。
状态压缩dp。虽然感觉不难,但是没能独立写出来。自己的代码估计是在关联的汉堡的处理上存在问题。
看了题解,很高兴基本套路没错,状态转移有问题(思路有问题)。
最后改为从后往前推,初始dp数组为-1,dp[0]=0,这样往后推,那么假如现在是dp[10100],处理到第5个汉堡,而第5个汉堡跟第1个和第3个相关联,那么在没有制作1和3时dp[10100]为-1,而为-1直接跳过,这样很好地处理了关联的问题。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; struct Node
{
int value;
int cost;
int cnt;
int rela[];
} ham[]; struct Node1
{
int value;
int cost;
};
Node1 dp[<<];
int main()
{
int t,kind,ener;
scanf("%d",&t);
while(t--)
{
memset(dp,-,sizeof(dp));
scanf("%d%d",&kind,&ener);
for(int i=; i<=kind; i++)
scanf("%d",&ham[i].value);
for(int i=; i<=kind; i++)
scanf("%d",&ham[i].cost);
for(int i=; i<=kind; i++)
{
scanf("%d",&ham[i].cnt);
for(int j=; j<ham[i].cnt; j++)
scanf("%d",&ham[i].rela[j]);
}
int en=<<kind;
int ans=;
dp[].cost=dp[].value=;
for(int j=; j<en; j++)
{
if(dp[j].value==-)
continue;
for(int i=; i<=kind; i++)
{
int tem=<<(kind-i);
if(j&tem)
continue;
int flag=;
for(int k=; k<ham[i].cnt; k++)
{
int temp=<<(kind-ham[i].rela[k]);
if(!(temp&j))
{
flag=;
break;
}
}
if(flag)
{
dp[j+tem].value=dp[j].value+ham[i].value;
dp[j+tem].cost=dp[j].cost+ham[i].cost;
}
}
}
for(int i=; i<en; i++)
{
if(dp[i].cost>ener)
continue;
if(ans<dp[i].value)
ans=dp[i].value;
}
printf("%d\n",ans);
}
return ;
}

HDU_3182_Hamburger Magi_状态压缩dp的更多相关文章

  1. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  2. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  3. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  4. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  5. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

  6. 状态压缩dp问题

    问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...

  7. BZOJ-1226 学校食堂Dining 状态压缩DP

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...

  8. Marriage Ceremonies(状态压缩dp)

     Marriage Ceremonies Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  9. HDU 1074 (状态压缩DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:有N个作业(N<=15),每个作业需耗时,有一个截止期限.超期多少天就要扣多少 ...

随机推荐

  1. swift编程语言基础教程 中文版

    swift编程语言基础教程 中文版 http://download.csdn.net/detail/u014036026/7845491

  2. android:省市县三级联动(基于json和spring)

    一.请看效果图": 二.程序的代码: 1.MainActivity.java package com.loveplusplus.loader.demo.ui; import org.json ...

  3. spring mvc +Mybatis3.1 整合的时候异常

    在使用Mybatis3.10+spring3.10+mybatis-spring-1.0.0集成,使用spring 时发生例如以下错误: 严重: Servlet.service() for servl ...

  4. tesnorflow Batch Normalization

    1.train或者从checkpoint restore后发现moving_mean和moving_variance都是0和1 bn1_mean = graph.get_tensor_by_name( ...

  5. VELT-0.1.6开发:载入根文件系统

    快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 VELT的全称是Vi ...

  6. YTU 2633: P3 数钱是件愉快的事

    2633: P3 数钱是件愉快的事 时间限制: 1 Sec  内存限制: 128 MB 提交: 387  解决: 215 题目描述 超市收银员的钱盒里,各种钞票总是按照面额分类整理,这样做可以提高效率 ...

  7. bzoj 2878: [Noi2012]迷失游乐园【树上期望dp+基环树】

    参考:https://blog.csdn.net/shiyukun1998/article/details/44684947 先看对于树的情况 设d[u]为点u向儿子走的期望长度和,du[u]为u点的 ...

  8. python实现汉诺塔程序

    # 汉诺塔思想笔记# 认识汉诺塔的目标:把A柱子上的N个盘子移动到C柱子# 递归的思想就是把这个目标分解成三个子目标# 子目标1:将前n-1个盘子从a移动到b上# 子目标2:将最底下的最后一个盘子从a ...

  9. (前缀和 内存分配)51NOD 1081 子段求和

    给出一个长度为N的数组,进行Q次查询,查询从第i个元素开始长度为l的子段所有元素之和.   例如,1 3 7 9 -1,查询第2个元素开始长度为3的子段和,1 {3 7 9} -1.3 + 7 + 9 ...

  10. SQL常用指令集(Oracle)

    1. Select rownum(oracle) top(mysql): 用于规定返回指定数目的值 Where roenum < number 2. Like 用于在where子句搜索指定模式 ...