Piggy-Bank

Piggy-Bank HDU - 1114(多重背包) 在 ACM 能够开展之前,必须准备预算,并获得必要的财力支持。该活动的主要收入来自于 Irreversibly Bound Money (IBM)。思路很简单。任何时候,某位 ACM 会员有少量的钱时,他将所有的硬币投入到小猪储钱罐中。这个过程不可逆,因为只有把小猪储钱罐打碎才能取出硬币。在足够长的时间之后,小猪储钱罐中有了足够的现金,用于支付 ACM 活动所需的花费。但是,小猪储钱罐存在一个大的... 阅读详情

Problem 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 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.
一个存钱罐,比空的时候多了一定的重量,然后给一些硬币的重量和价值,判断这存钱罐里面最少有多少钱。
将区间离散化,然后dp[i+weigh]=min(dp[i+weigh],dp[i]+value);
一直更新就可以。

include

include

include

include

using namespace std;
long long min(long long a, long long b)
{
return a < b ? a : b;
}
long long dp[10005];
struct Piny{
long long value;
long long weigh;
}piny[505];
int main()
{
long long i, n, j, m, ans, t, e, f, inf = 999999;
cin >> t;
while (t–)
{
cin >> e >> f;
cin >> n;
for (i = 1; i <= n; i++)
cin >> piny[i].value >> piny[i].weigh;
for (i = 1; i <= f; i++)
dp[i] = inf;
for (i = 1; i <= n; i++)
{
if (e + piny[i].weigh <= f)
dp[piny[i].weigh + e] = piny[i].value;
}
dp[e] = 0;
for (i = 1; i <= n; i++)
{
for (j = e; j <= f; j++)
{
if (dp[j] != inf && j + piny[i].weigh <= f)
{
dp[j + piny[i].weigh] = min(dp[j + piny[i].weigh], dp[j] + piny[i].value);
}
}
}
/*for (i = e; i <= f; i++)
cout << dp[i] << ” “;*/
if (dp[f] == inf)
cout << “This is impossible.” << endl;
else
cout << “The minimum amount of money in the piggy-bank is ” << dp[f] << “.” << endl;
}
return 0;
}

聚类分析之——Kmeans算法(一) 原创地址:http://www.toutiao.com/i6399454239554273794/ 聚类分析是一种静态数据分析方法,常被用于数据挖掘、机器学习、模式识别等领域,聚类是一种无监督式的学习方法。它是在未知样本类别的情况下,通过计算样本彼此间的距离(欧式距离,马式距离,汉明距离,余弦距离等)来估计样本所属类别。从结构性来划分,聚类方法分为自上而下和自下而上两种方法。聚类的算法有很多 阅读详情

相关推荐

实战对比:Lmcache+vllm将KVcache卸载到CPU和SSD的性能差异(附完整配置)

本文通过实战对比Lmcache与vLLM在KV Cache卸载到CPU和SSD的性能差异,详细解析了配置优化、基准测试及高级调优策略。实验显示,CPU卸载在低并发下表现优异,而SSD方案在高并发场景中更具性价比优势,为LLM推理任务提供了高效的存储解决方案。

weixin_30664051的博客 700

Piggy-Bank (完全背包)

完全背包: 完全背包(CompletePack): 有N种物品和一个容量为V的背包,每种物品都有无限件可用。第i种物品的费用是c[i],价值是w[i]。求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大。 完全背包按其思路仍然可以用一个二维数组来写出: f[i][v]=max{f[i-1][v-k*c[i]]+k*w[i]|0&lt;=k*c[i]&lt;=v} 同...

chen_zan_yu_的博客 431

安装部署 Guacamole 远程桌面网关

Guacamole 是Apache基金会提供的一组基于web的远程桌面访问工具,支持 VNC、RDP、SSH、 Telnet 等协议,支持远程透传音视频。

UsamaBinLaden6976498的专栏 1963

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

四类九种移位寄存器总结(循环(左、右、双向)移位寄存器、逻辑和算术移位寄存器、串并转换移位寄存器、线性反馈移位寄存器LFSR|verilog代码|Testbench|仿真结果)

移位寄存器有哪些分类呢? 按移位方向分类:①单向移位寄存器(包括左移、右移)②双向移位寄存器 按循环方式分类:①循环移位寄存器②非循环移位寄存器 按部位的不同分类:①逻辑移位寄存器②算术移位寄存器 按输入输出方式分类:①串入串出②串入并出③并入串出④并入并出

Loudrs的博客 1万+

用人话讲明白线性回归LinearRegression

目录 什么是回归 一元线性回归 损失函数 最小二乘估计 小结 1. 什么是回归 当我们学习一门新课程、接触一个新专业时,总会对该领域的专有名词感到困惑,甚至看完解释仍难以理解其含义。在我们一起学习machine learning的过程中,我会尽量对相关名词用“人话”做一遍解释,以减少学习的“痛苦感”。 譬如今天要学的线性“回归”,这个回归(regression)和我们平时说的“回归祖国”的回...

化简可得 1万+

HDUOJ 1114 Piggy-Bank

HDUOJ 1114 Piggy-Bank 题目链接 Problem 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 behind is simple. Wheneve

旺崽的博客 2585

实战演练:用wvp-GB28181-pro + ZLMediaKit搭建一个可用的国标视频监控测试环境(附设备模拟器对接)

本文详细介绍了如何使用wvp-GB28181-pro和ZLMediaKit在Ubuntu系统上搭建GB28181视频监控测试环境。从环境准备、组件解析到核心服务部署与设备模拟器对接,提供完整的实战指南,帮助开发者快速构建可验证的监控系统。

weixin_42692935的博客 579

HDOJ Piggy-Bank

Piggy-Bank http://acm.hdu.edu.cn/showproblem.php?pid=1114 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe

欢迎 702

SAP采购申请审批策略配置简介

SAP采购申请审批策略配置简介 1、CT04创建特征

我小时候很黑的博客 8159

在 Esp32 摄像头上实现边缘脉冲 FOMO 物体检测

本文将详细介绍如何在 Esp32 摄像头上实现边缘脉冲 FOMO 物体检测,并提供实现源码

DT程序员的博客 704

acm Piggy-Bank

题目:王道机试指南 P241-例题 12.8 Piggy-Bank 一、核心:如果想要避免一维数组的 逆序还是顺序 问题的话,应该使用 二维数组dp[][] , 关键在于初始化。 dp[i][j] : 表示 第i 件商品,容量大小为j 的背包,最少能放的硬币价值。 初始化为 i\j 0 1 2 3 4 … 0 0 ∞ ∞ ∞ ∞ … 1 0 2 0 3 0 … … 二、状态转移方程 dp[i][j]={ dp[i−1][

竦貊的博客 326

ConvNeXt 系列改进:二次创新 ConvNeXt:结合 RepVGG 结构重参数化,训练多分支、推理单路

2026年的视觉模型赛道呈现出一种有趣的“返璞归真”趋势——在Transformer狂飙数年之后,卷积网络正以全新的姿态回归。这其中,ConvNeXt无疑是纯卷积阵营中最耀眼的明星。从2022年Meta AI首次提出至今,ConvNeXt系列已经走过了近四年的演进之路,衍生出ConvNeXt V2、E-ConvNeXt等多个增强版本。ConvNeXt的7×7深度卷积带来了不错的感受野,却也埋下了推理效率的隐患。

ZXSXJ的博客 232

[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

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

F - Piggy-Bank

F - Piggy-Bank 题目入口:F - Piggy-Bank 杭电入口:Piggy-Bank 解题思路 t组测试样例 e为空猪重量 f为实猪重量 lim = f-e为给定硬币最终重量 n种硬币不限数量(这里要想到完全背包) wei[]存放硬币重量 val[]存放硬币币值 dp[i]为达到重量i所需要的硬币最小价值 所以未放入硬币前这里我们初始化为无穷大inf 当然dp[0] = 0 接下...

恒治学 215

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

hud 1114 Piggy-Bank

题目描述:                                                        Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5814    Accepted Sub

utoppia is another word . 547

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

(完全背包)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

hdu acm 1114 Piggy-Bank

Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16443    Accepted Submission(s): 8299 Problem Description Before ACM can

人生如梦,浮华一瞬间的专栏 461

SWUST OJ 之 0676 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...

DreamShadow的博客 435

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 && poj 1384 Piggy-Bank

hdu   1114    Piggy-Bank                  题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114                      题目大意:储蓄罐里有一些硬币,硬币重量已知,所有硬币种类(重量、价值)给出,问这堆硬币最少价值是多少。 题目分析:标准的完全背包,略有不同之处是求最少价值。

slicer的技术交流栈 1300

题解: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...

晚安( ̄o ̄) . z Z 440

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
上一篇: Exam
下一篇: Robbers
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值