Piggy-Bank (完全背包)

POJ1384 Piggy Bank(完全背包与“恰好”) 已经是我的第四篇题解了hhhh 在这篇题解中,我们会讲到背包中“恰好”的概念以及它的使用方法。 —————————————————————————————————— 原题 POJ1384 Piggy Bank 题意 给出存钱罐中钱的总重量,给出每种钱的价格和重量(数量不限),求存钱罐中钱的最小价值最少为多少钱。 思路 变体的完全背包。 完全背包的两个状态转移方程: f[i][j] = max(f[... 阅读详情

 Piggy-Bank

 
Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any small money, he takes all the coins and throws them into a piggy-bank. You know that this process is irreversible, the coins cannot be removed without breaking the pig. After a sufficiently long time, there should be enough cash in the piggy-bank to pay everything that needs to be paid. 

But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs! 
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing two integers E and F. They indicate the weight of an empty pig and of the pig filled with coins. Both weights are given in grams. No pig will weigh more than 10 kg, that means 1 <= E <= F <= 10000. On the second line of each test case, there is an integer number N (1 <= N <= 500) that gives the number of various coins used in the given currency. Following this are exactly N lines, each specifying one coin type. These lines contain two integers each, Pand W (1 <= P <= 50000, 1 <= W <=10000). P is the value of the coin in monetary units, W is it's weight in grams. 
Output
Print exactly one line of output for each test case. The line must contain the sentence "The minimum amount of money in the piggy-bank is X." where X is the minimum amount of money that can be achieved using coins with the given total weight. If the weight cannot be reached exactly, print a line "This is impossible.".
Sample Input
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
Sample Output
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.

题目大意:称出背包装物品前后的重量,求最小价值。

完全背包问题:

#include <iostream>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
int main(){
	int T;
	cin >> T;
	while(T--){
		int w1,w2;
		cin >> w1 >> w2;
		int v[505],w[505];
		int dp[10100];
		int i,j;
		int n;
		cin >> n;
		for(i = 1; i <= n; i++){
			cin >> v[i] >> w[i];
		}
		for(i = 1; i <= w2-w1; i++)
		  dp[i] = INF;
		dp[0] = 0;
		for(i = 1; i <= n; i++){
			for(j = w[i]; j <= w2-w1; j++){
				dp[j] = min(dp[j],dp[j-w[i]]+v[i]);
			}
		}
        if(dp[w2-w1] == INF)
          cout << "This is impossible." << endl;
        else
          cout << "The minimum amount of money in the piggy-bank is " << dp[w2-w1] << "." << endl;
	}
	return 0;
}


嵌入式系统存储体系 主要分为三种:高速缓存(cache)、主存和外存。 阅读详情

相关推荐

UWB定位原理详细介绍

Hello大家好我是小智,今天我来给大家介绍下超宽带的定位原理,首先我们来讲下什么是UWB技术。 超宽带(Ultra Wide Band)简称UWB,和我们熟悉的WIFI、蓝牙技术一样属于通信技术的一种,UWB是一种无线载波通信技术,它不采用正弦载波,而是利用纳秒级的非正弦波窄脉冲传输数据,其所占的频谱范围很宽,右图是一种典型的正弦载波信号图。 UWB这种技术有什么特点呢? UWB系统结构实现简单;2.具有高速的数据传输能力;3.功耗低;4.安全性高;5.多径分辨能力强;6.可用于精确定位等特点。 UWB.

qq_35699674的博客 2万+

Piggy-Bank HDU - 1114(完全背包)

Piggy-Bank HDU - 1114 Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any

一直努力 232

LSTM量化选股实战:从数据清洗到回测归因的工程化闭环

LSTM(长短期记忆网络)是一种专为建模长程依赖而设计的循环神经网络,其门控机制能有效应对金融时序数据的非线性、高噪声与动态演化特性。相比传统统计模型或简单RNN,LSTM在股价趋势建模中展现出更强的鲁棒性与泛化能力,尤其适合处理日频多因子时序信号。其技术价值不仅在于提升预测精度,更在于支撑可归因、可审计的量化策略工程实践——从特征构建、标签定义到滚动回测,每一步都需严防未来信息泄露与过拟合风险。典型应用场景包括A股多因子选股、行业轮动信号生成及Alpha组合优化。本文聚焦LSTM在真实量化场景中的落地难点

weixin_33158887的博客 397

Piggy-Bank(完全背包)

Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simp...

zhiyeegao的博客 5547

Autosar中CAN信号传输的模块化解析与实战应用

本文深入解析了AUTOSAR架构下CAN信号传输的模块化流程,详细阐述了从应用层软件组件(SWC)到COM模块打包、PduR路由、CanIf硬件抽象直至Can Driver驱动的完整“流水线”。文章通过实战案例,重点说明了模块化设计如何实现解耦与可移植性,并提供了关键模块配置要点与调试技巧,旨在帮助开发者构建高可靠、实时的车载通信系统。

g9h0i1的博客 901

Allegro Design Entry CIS 与 OrCAD Capture CIS:PCB设计工具链中的双雄对决

本文深入对比了Cadence旗下两大原理图设计工具Allegro Design Entry CIS与OrCAD Capture CIS。Allegro Design Entry CIS源自Concept HDL,定位高端,强调自顶向下的层次化设计和与Allegro PCB Editor的无缝约束管理,适合大型复杂系统及团队协作。OrCAD Capture CIS则以其出色的易用性、广泛的兼容性和强大的CIS数据库功能著称,是中小型项目及跨工具链协作的通用选择。文章从历史渊源、核心功能、适用场景等多维度剖析,

bush的博客 486

Piggy-Bank(背包九讲_完全背包)

Piggy-BankCrawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Before ACM can do anything, a

Rocky0429 1487

DNF单机版搭建全攻略:从零开始到局域网联机(含常见问题解决)

本文提供详细的DNF单机版搭建指南,从环境配置到局域网联机设置,涵盖服务端安装、数据库配置及常见问题解决方案。适合新手和有经验的玩家,帮助快速搭建专属游戏服务器,重温经典游戏体验。

weixin_30832143的博客 844

Piggy-Bank HDU - 1114 完全背包 (基础dp专题)

在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持。该活动的主要收入来自于 Irreversibly Bound Money (IBM)。思路很简单。任何时候,某位 ACM 会员有少量的钱时,他将所有的硬币投入到小猪储钱罐中。这个过程不可逆,因为只有把小猪储钱罐打碎才能取出硬币。在足够长的时间之后,小猪储钱罐中有了足够的现金,用于支付 ACM 活动所需的花费。 但是,小猪储钱罐存在一个大的问题,即无法确定其中有多少钱。因此,我们可能在打碎小猪储钱罐之后,发现里面的钱不够。显然,我们希望避免这种不愉

qq_45891413的博客 204

前端开发学习--登录和注册页面设计(html和css,可完成两个页面点击切换)

今天学习了登录和注册页面的设计,主要是HTML和CSS部分,注册和切换采用了Js代码进行,后面将通过js进行填写内容的验证,进而可通过JSP跳转到Servlet进行DAO数据的校验,这属于后端部分了。 总体设计思路:整个页面设计可以分为主体(content)、头部(content-header)、内容(content-body)三个部分组成,其中是主体是根部,包含了头部和内容,头部和内容各自下设两...

weixin_43691879的博客 1万+

UG NX二次开发(C++)-NX2406系列二次开发编程模板配置

前面已经写了有关UG NX二次开发编程模板配置的文章,但是由于NX2406/2412系列的版本中,在UGOpen文件夹中没有了vs_files文件夹了,而是采用了VSIX Project的方式配置(其适用于VS2019),在VS2022中不能正确的配置。我结合以前配置模板的经验和现在的配置方式讲一下NX2406系列二次开发编程模板的配置。我把相应的编程模板放在资源文件UG NX二次开发编程模板(基于NX2406版本制作)中,方便大家下载使用。

GimiGimmy 2640

[dp]Piggy-Bank 完全背包

Description Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea

童凌的技术博客 778

使用GeoServer发布WMS动态地图服务,使用openlayers访问wms服务浏览地图数据

GEOServer是java版开源工具,使用GEOServer简单几步就可以搭建自己的地图服务,与小伙伴们共享地图数据。 一、使用GEOServer发布WMS动态地图服务 大致步骤如下: 1. 新建工作区 左边菜单栏,工作区,新建,起个名字,设置url。 2. 选择数据源 左边菜单栏,选择“数据源”,点击“添加新的数据源”,常用的有shp、postgresql数据库,根据自己的需要选择,这里选择了shp文件源。 选中存放在刚才新建的工作区下面,给数据源起个名字,选择文件本机存放位置,设置编码,包含中文属

从地图看世界的专栏 4538

(完全背包)HDU1114Piggy-Bank

HDU1114Piggy-Bank 题意&思路: 给你存钱罐初始和存钱后的重量E,F,金钱的种类N,每种金钱的价值V和重量W。求最少的价值为多少。 完全背包的模板题,主要注意是他求得是最小值。 代码: #include<bits/stdc++.h> const int N=1e5+10; const int mod=1e7+9; const int maxn=0x3f3f3f3...

Z7784562的博客 233

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

HDU-1114 Piggy-Bank(完全背包讲解以及它的的三种做法)

Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description Before ACM can do anything, a budget must be prepared and the necessary financial sup...

孤风的博客 816

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

HDU 1114 Piggy-Bank 完全背包

HDU 1114 Piggy-Bank 完全背包 Problem Description 来源:http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1013&ojid=0&cid=13029&hide=0 Before ACM can do anything, a budget must be prepa...

qq_fairy橙 的博客 194

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

POJ 1384 Piggy-Bank(完全背包)

POJ 1384 Piggy-Bank(完全背包) http://poj.org/problem?id=1384 题意: 现在有n种硬币,每种硬币有特定的重量cost[i] 克和它对应的价值val[i]. 每种硬币可以无限使用. 已知现在一个储蓄罐中所有硬币的总重量正好为m克, 问你这个储蓄罐中最少有多少价值的硬币? 如果不可能存在m克的情况, 那么就输出” This is impossible.”.

code 2990

HDU - 1114 Piggy-Bank(完全背包

HDU - 1114 Piggy-Bank TEST<30> 11-18 解题思路 …难受哇~ 完全背包的 模板题 只不过时最小 问题 下文ac代码使用 滚动数组 写法 AC 代码如下 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

MaxVen 264

完全背包:Piggy-Bank猪猪储蓄罐

完全背包:Piggy-Bank猪猪储蓄罐 Time Limit:1000MS Memory Limit:65536KTotal Submit:14 Accepted:6 Description Before ACM can do anything, a budget must be prepared and the necessary financial support obta...

akui7399的博客 408

完全背包]HDU 1114 Piggy bank

HDU 1114 piggy bank 完全背包问题

昨天的我现在的未来 532

POJ 1384 Piggy-Bank (完全背包)

Piggy-Bank 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/F Description Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main ...

dituonian8372的博客 188

HDU 1114 Piggy-Bank ( 完全背包 )

一道典型的完全背包问题~ 完全背包就是把01背包的第二个for循环从小到大循环就好 Piggy-Bank Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 72   Accepted Submission(s)

sky_fighting的专栏 722

完全背包变形--hdu-1114-Piggy-Bank

Piggy-Bank

lele_pipi 464

HDU 1114 Piggy-Bank 【完全背包】

题目链接

u013180220的专栏 427

【模板】动态规划之背包问题(01背包、多重背包、完全背包) (邮票、Piggy-bank题解)

DP求解核心:状态转移方程和边界条件。 最朴素的01背包问题 注意点: 1. 理解dp[][]的意义,表示前i种物品在重量为j时的最大价值。 2. 在选择放入物品时,注意对背包大小判断。 //二维数组 #include<iostream> #include<cstring> #include<algorithm> #define N 10...

coderwait 934
上一篇: Bone Collector (简单dp)
下一篇: Permutations CodeForces - 189C(思维)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值