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 ...
随机推荐
- Pymsql
Pymsql 1.创建数据库连接 pymsql connect conn=pymysql.connect(host="localhost",user="root" ...
- re模块中的compile函数
compile compile(pattern,flag=0) compile a regular expression pattern,return a pattern object compile ...
- 微信小程序:模板消息推送提示{“errcode”:41030,”errmsg”:”invalid page hint: [gP1eXXXXXX]”}
在开发小程序 模板消息定时推送功能时,在开发版测试程序功能运行正常,但提交到线上后提示报错{“errcode”:41030,”errmsg”:”invalid page hint: [gP1eXXXX ...
- 使用生成器把Kafka写入速度提高1000倍
title: 使用生成器把Kafka写入速度提高1000倍 toc: true comment: true date: 2018-04-13 21:35:09 tags: ['Python', '经验 ...
- Delphi X10.2 + FireDAC 使用 SQL 语句 UPDATE
MainForm.Conn.StartTransaction; UserManagerQuery.SQL.Clear; UserManagerQuery.SQL.Text := 'UPDATE tab ...
- 学习React系列(四)——受控组件与非受控组件
受控组件:通过组件的状态与属性的改变来控制组件 不可控组件:直接通过底层的dom来控制组件(具体来说就是通过绑定再底层dom上的方法来实现的,比如说ref,onChange) 受控组件 functio ...
- Java多线程之interrupt()的深度研究
近期学习Java多线程的中断机制,网上的帖子说得很浅,并没深究其原理.看了Java源码,对Java的中断机制有了略深入的理解,在这篇文章中向感兴趣的网友分享下.这篇文章主要通过一个典型例子对中断机制进 ...
- Hibernate注解开发详解
*****************关于注解的简单介绍 详细介绍请点击这里注解详细教程 package com.tomowork.pojo; import org.hibernate.annotatio ...
- angularjs中使用 <input type="file">标签实现一次最多上传5张图片
前期准备: 1.angular.js 2.bootstrap.css 具体如何实现呢?请看下面代码哈哈哈. 在angular项目中,如果要给<input type="file" ...
- Anaconda入门安装教程
Anaconda 是什么? Anaconda 是一个可用于科学计算的 Python 发行版,支持 Linux.Mac.Windows系统,内置了常用的科学计算包.它解决了官方 Python 的两大痛点 ...