ACM Piggy Bank
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!
(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.
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.".
#include<bits/stdc++.h>
using namespace std;
const int INF = << ;
int main()
{
int T,E,F,N,P,W;
int dp[];
while(cin>>T)
{
while(T--)
{
dp[] = ;
scanf("%d %d",&E,&F);/*E为weight of an empty pig ,F为装满硬币的存储罐的重量*/
scanf("%d",&N); /*硬币的种类*/
for(int i = ; i <= F; i++)
dp[i] = INF;
for(int i = ; i < N; i++)
{
scanf("%d %d",&P,&W); /*P为硬币的面值 W为硬币的重量*/
for(int j = W; j <= F-E; j++)
dp[j] = min(dp[j],dp[j-W]+P);
}
if(dp[F-E] == INF ) cout<<"This is impossible."<<endl;
else cout<<"The minimum amount of money in the piggy-bank is "<<dp[F-E]<<"."<<endl;
}
} return ;
}
ACM Piggy Bank的更多相关文章
- POJ1326问题描述
Description Mileage program of ACM (Airline of Charming Merlion) is really nice for the travelers fl ...
- Android开发训练之第五章第五节——Resolving Cloud Save Conflicts
Resolving Cloud Save Conflicts IN THIS DOCUMENT Get Notified of Conflicts Handle the Simple Cases De ...
- luogu P3420 [POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can either be opened with its correspon ...
- 洛谷 P3420 [POI2005]SKA-Piggy Banks
P3420 [POI2005]SKA-Piggy Banks 题目描述 Byteazar the Dragon has NN piggy banks. Each piggy bank can eith ...
- [Luogu3420][POI2005]SKA-Piggy Banks
题目描述 Byteazar the Dragon has NNN piggy banks. Each piggy bank can either be opened with its correspo ...
- 深度学习之加载VGG19模型分类识别
主要参考博客: https://blog.csdn.net/u011046017/article/details/80672597#%E8%AE%AD%E7%BB%83%E4%BB%A3%E7%A0% ...
- 【阿菜Writeup】Security Innovation Smart Contract CTF
赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...
- ImageNet2017文件下载
ImageNet2017文件下载 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PASCAL ...
- ImageNet2017文件介绍及使用
ImageNet2017文件介绍及使用 文件说明 imagenet_object_localization.tar.gz包含训练集和验证集的图像数据和地面实况,以及测试集的图像数据. 图像注释以PAS ...
随机推荐
- UVAlive-2554 Snakes & Ladders---BFS状态的存储
题目链接: https://vjudge.net/problem/UVALive-2554 题目大意: 题目的大概意思是又N*N的棋盘,编号从1 到 N*N 棋盘中分布着蛇和梯子玩家在位置1处, ...
- 1.2WEB API 跨域
详细请参考http://www.cnblogs.com/landeanfen/p/5177176.html 在项目上面使用Nuget安装 microsoft.aspnet.webapi.cors 在w ...
- easygui的导入方式
方法一: >>> import easygui >>> easygui.msgbox('hello') 方法二: >>> from easygui ...
- innerHTML与innerText的区别
innerHTML获取元素的HTML内容,和设计元素的HTML内容(HTML标签会被解析)例如:ele.innerHTML="<strong>我会被解释加粗</strong ...
- 单例模式详解及java常用类
[单例模式] 确保某一个类,只能产生一个实例. 设计思路: ====将构造函数私有化,确保类外部,不能使用new关键字自行创建对象. ====在类内部实例化一个对象,并通过静态方法返回. ( ...
- 那些年,曾踩过的Spark坑
1.报错18/01/25 14:56:58 ERROR executor.CoarseGrainedExecutorBackend: Driver 127.0.0.1:37159 disassocia ...
- 如何用.reg文件操作注册表
Windows Registry Editor Version 5.00 ;删除值 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpi ...
- Struts2笔记分享(一)
Struts2概述1.简介Struts就是在Model2的基础上实现的一个MVC框架,它只有一个中心控制器,采用XML定制的转向的URL,采用Action来处理逻辑.2.Struts2的MVC模式MV ...
- 热力图heatmap.js使用中的思路解析
官网: https://www.patrick-wied.at/static/heatmapjs/ 需求:使用heatmap.js制作热力图,反映人群分布情况 问题:热力图需要的数据:坐标 + 人数 ...
- JEECG 新版在线文档WIKI正式发布
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/zhangdaiscott/article/details/80 JEECG 新版在线文档WIKI正式 ...