HDU 3182 Hamburger Magi(状压dp)

别再拍脑袋估工时了!手把手教你用FPA功能点分析法,给软件项目算笔明白账 本文详细介绍了FPA功能点分析法在软件开发工作量评估中的应用,帮助团队告别拍脑袋估算。通过量化系统功能组件,FPA提供客观的工时和成本预估,特别适合需求不明确的项目初期。文章以财务系统为例,拆解FPA计算流程,并分享实用估算模板,助力技术管理者提升项目规划能力。 阅读详情

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
 
题意:n个货物,和有的总的钱,然后每一个物体的价值,然后n个物体的花费,然后,是每拿第i种物品时必须已经有的物品


思路:状压dp




#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 1005

int dp[1<<17],ss[1<<16];
int cost[N],va[N];
int n,all,ca[1<<16];

void solve()
{
	int i,j;

	mem(ss,0);

	mem(dp,-1);
	dp[0]=0;

	int len=1<<n;

	int cur;

	fre(cur,0,len)
	{

		if(dp[cur]==-1) continue;

		fre(j,1,n+1)
			{
				if(cur&(1<<(j-1))) continue;

				int to;

				if((cur&ca[j])!=ca[j]) continue;

				to=cur|(1<<(j-1));

				if(dp[cur]+va[j]>dp[to]&&ss[cur]+cost[j]<=all)   //可以更优的到达to,并且花的钱不超过all
				{
					dp[to]=dp[cur]+va[j];
					ss[to]=ss[cur]+cost[j];
				}

			}

	}
	int ans=0;
	fre(cur,0,len)
	   ans=max(ans,dp[cur]);

	pf("%d\n",ans);

}

int main()
{
	int t,i,j;
	sf(t);
	while(t--)
	{
		sff(n,all);

		fre(i,1,n+1)
		  sf(va[i]);

		fre(i,1,n+1)
		  sf(cost[i]);

		mem(ca,0);

		int x,k;


		fre(i,1,n+1)
		{
			sf(k);
			while(k--)
			{
				sf(x);
				ca[i]=ca[i]|(1<<(x-1));
			}
		}

		solve();

	}
   return 0;
}


STM32F401RET6寄存器手册阅读标记 对于时钟树配置,可参考STM32CubeMX中的时钟树配置,STM32CubeMX将基础配置图像化,较为简单。RCC_CR寄存器的HSIRDY位为只读位,当读取值为1时,表示HSI振荡器准备就绪,当HSION位被设置时,HSIRDY会自动设置为低电平。//问题标记:USART配置寄存器信息是如何与USART1/2/3建立联系的(为什么不是三个分别配置)查阅寄存器手册可知,需要配置时钟的模块有:USART1,IO port A。(2)TX配置方法(寄存器手册512页)(4)配置寄存器(寄存器手册548页) 阅读详情

相关推荐

本地部署Llama 3中文版:Ollama量化配置与调优指南

大模型本地部署正在成为数据敏感场景下的主流选择。本地运行开源大模型,既能保护隐私又能降低调用成本,但中文能力往往成为瓶颈。以Llama 3为代表的开源模型,需借助中文微调与量化技术,才能在消费级显卡上流畅运行。量化通过压缩模型权重减小显存占用,配合Ollama等推理框架,可快速搭建私有中文AI服务。该方案适用于知识库问答、内容生成、离线助手等场景,并可通过OpenAI兼容接口无缝对接Dify等应用平台。本文从硬件选型、量化等级到Modelfile配置,系统梳理本地部署中文大模型的全链路实战方法与排错思路,帮

weixin_29035405的博客 82

Hamburger Magi(hdu 3182)

Hamburger Magi Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 437Accepted Submission(s): 144 Problem Description In the mysterious ...

weixin_30496431的博客 167

Windows沙盒神器Sandboxie Plus保姆级教程:从安装到实战测试可疑软件

本文详细介绍了Windows沙盒神器Sandboxie Plus的安装、配置与实战应用,帮助用户安全测试可疑软件。从系统要求、安装步骤到核心功能如多沙盒管理、文件共享和快照恢复,全面解析了这款轻量级沙盒工具的优势与使用技巧,特别适合需要隔离运行未知程序的用户。

weixin_29323049的博客 1153

Hamburger Magi(hdu 3182)

Hamburger Magi Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Problem Description In the mysterious forest, there is a group of Magi. Most of them like to eat hum

残阳止水 411

自动驾驶仿真:python和carsim联合仿真案例

carsim内部有许多相关联合仿真的demo,simulink、labview等等都有涉及,这里简单介绍下python和carsim联合仿真的方法,虽然carsim官方有个Steer_Control.py相关的案例,但是感觉比较冗余,这里抽出重点部分和大家交流探讨下。提示:以下是本篇文章正文内容,下面案例可供参考1、这里关于solvers的细节其实都没说,因为里面确实也没什么内容好讲的,本质就是调用carsim.dll,如果你需要更多的函数解析其实可以看vs_api.h,路径在,具体内容如下图所示。

zataji的博客 9060

泛微ecology9 HRMwebservice接口实战:企业组织架构与人员信息同步指南

本文详细介绍了泛微ecology9 HRMwebservice接口在企业系统集成中的实战应用,重点解析了如何通过该接口实现组织架构与人员信息的双向同步。内容涵盖环境配置、核心接口调用、数据格式规范及常见错误排查,旨在帮助开发与运维工程师高效完成主数据同步,提升企业IT管理效率。

weixin_29323365的博客 498

HDU 3182 Hamburger Magi(状压DP解决有顺序背包问题)

Hamburger Magi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description In the mysterious forest, there is a group of Magi. Most of them l

MR CODER 397

c#源码,将矩阵(二维数组)渲染成云图,强度图,热力图,均匀性图,伪彩图

优快云软件0积分下载链接:https://download.youkuaiyun.com/download/wanghuannihao1992/86656759。6、渲染效果良好,颜色均匀分布,不存在等高线,交叉点。3、纯粹的C#代码编写,不含第三方dll或者控件。4、支持ColorBar显示,强度值颜色坐标显示。2、渲染时间60ms左右,速度快,1、二维数据最小支持2*2,7、采样全新数据插值算法。先直接上C#软件效果图。5、整图保存为单个图片。

业余程序员小徐的博客 6880

[状压dp]HDOJ3182 Hamburger Magi

题意 大致是: 有n个汉堡 m块钱 (n<=15)      然后分别给n个汉堡的能量       再分别给n个汉堡所需的花费     然后下面n行 第i行有x个汉堡要在i汉堡之前吃 然后给出这x个汉堡的编号 输出 能获得的最大能量 分析: n那么小, 很明显状压 状压吃的顺序 每个汉堡的花费是固定的, 因此只要一维的dp 再加个数组 记录当前状态的花费...

aicheng4794的博客 156

OpenCV实现物体尺寸的测量

物体尺寸测量的思路是找一个确定尺寸的物体作为参照物,根据已知的计算未知物体尺寸。如下图所示,绿色的板子尺寸为220*300(单位:毫米),通过程序计算白色纸片的长度。

qq_53545309的博客 9157

Qt + windows + Linux+QtInstallerFramework打包教程

本文介绍了使用Qt Installer Framework在Windows和Linux系统下打包Qt应用程序的完整教程。Windows部分详细说明了从下载安装框架、配置环境变量、生成release版本,到创建安装包目录结构和修改配置文件的完整流程。Linux部分则重点讲解了环境变量设置、桌面应用配置(.desktop文件)以及两种打包方案:一种使用linuxdeployqt生成AppImage文件,另一种采用类似Windows的安装包方式。教程提供了关键配置文件(config.xml、package.xml

Qt历险记,专注Qt技术,三年医疗设备研发经验,1年机器视觉研发经验,半年柔性传感研发经验。 516

HDU 3182 Hamburger Magi (状态压缩DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 #include&lt;bits/stdc++.h&gt; using namespace std; #define debug puts("YES"); #define rep(x,y,z) for(int (x)=(y);(x)&lt;(z);(x)++) #define read(x,...

满月照亮的路 274

39、FIPA ACL:多代理系统中的标准化通信

本文详细介绍了FIPA ACL(Agent Communication Language)的基本概念、言语行为理论基础以及其在多代理系统(MAS)中的应用。文章涵盖了FIPA ACL的消息格式、信息交流流程、实现与优化方法,并通过智能调度系统的实例展示了其实际应用效果。此外,还探讨了FIPA ACL面临的挑战及未来发展方向,如通信延迟优化、本体简化、安全性增强等。

k8s6orchestrator的博客 381

HDU 3182 Hamburger Magi(状压DP)

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

sulisulisu的博客 394

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

HDU3182 Hamburger Magi【状压DP】

题目链接:Hamburger Magi 分析:每种汉堡只能做一次,恰好就是0~(1<<n)-1的所有状态; #include<bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int maxn=(1<<15)+100; int dp[ma...

MaJorieL 187

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

hdu 3182 Hamburger Magi(状压dp)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 预处理+dp #include #include #include using namespace std; const int N=15; int val[N],cost[1<<N],energy[N],last[N]; int dp[1<<N]; int n,m; void init() {

a709743744的博客 499

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

hdu3182---Hamburger Magi(状压dp)

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 ha

Alex 1246

HDU3182 - Hamburger Magi(状压DP)

题目链接 HDU3182 【题意】

转移到dawxy.com 685

【DP】 HDU 3182 Hamburger Magi 状压

汉堡间有先吃后吃的关系

Kewowlo 713

hdu_3182_Hamburger Magi(状压DP)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3182 题意:有n个汉堡,做每个汉堡需要消耗一定的能量,每个汉堡对应一定的价值,且只能做一次,并且做当前汉堡需要先做出列出的汉堡,求最大的价值 题解:状压DP #include #define FFC(i,a,b) for(int i=a;i<=b;++i) int T,n,all,end,no

bin_gege的博客 400

HDU - 3182:Hamburger Magi(状压DP)

Hamburger Magi                                                        Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)                                          

Mitsuha_的博客 577

HDU5823(状压DP)

给你一个n个点的图,问每个子集的最小色数 题解:每个子图的染色问题,可以看成是找每个子图的独立集问题(两两顶点互不相邻的图叫独立集),可以先枚举每个状态,然后枚举每个顶点,表示以这个顶点为起始的子图,再枚举每个顶点,表示这个顶点和上面那个顶点所构成的图是一个独立集,预处理出所有非法的状态,即他们之间有边。 首先预处理出每个点集的子集是否为独立集. 然后令dp[S]表示点集S的导出子图的

nucshiyilang的博客 464

HDU 3182 Hamburger Magi

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3182 题意:有n个汉堡,每个汉堡有一个价值和做汉堡需要的体力,并且做有些汉堡前需要先做别的汉堡,问最多能做出多大价值 每个汉堡只能做一次并且有先后顺序,所以需要状压dp而不能直接暴力判断 做汉堡的前置关系可以用状压来简化判断 还可以预处理出每个状态需要花费的体力 #inclu...

dengyaodan0206的博客 160
上一篇: CF 205 C Little Elephant and Interval(模拟)
下一篇: ural 1057 Amount of degrees (数位dp)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值