Piggy-Bank (hdoj1114)
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<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int E,F,W;
int v[],w[],p[];
int n;
void dp()
{
int i,j;
for(i=;i<=n;i++)
for(j=w[i];j<=W;j++)
p[j]=min(p[j],p[j-w[i]]+v[i]);
}
int main()
{
int i,j;
int T;
cin>>T;
while(T--)
{
cin>>E>>F;
W=F-E;
cin>>n;
for(i=;i<=W;i++)
p[i]=;
for(i=;i<=n;i++)
cin>>v[i]>>w[i];
p[]=;
dp();
if(p[W]==)
cout<<"This is impossible."<<endl;
else
cout<<"The minimum amout of money in the piggy-bank is "<<p[W]<<"."<<endl;
}
return ;
}
Piggy-Bank (hdoj1114)的更多相关文章
- PAT 1017 Queueing at Bank (模拟)
1017. Queueing at Bank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Supp ...
- JZ2440开发笔记(6)——存储控制器
存储控制器与CPU及其它外设的关系 我们看到cpu上集成了一个存储管理器,外围的存储设备都接在这个存储管理器上.cpu负责发出命令,其它的一切工作都交给了存储管理器.那么存储管理器是如何来管理这些外设 ...
- Web安全相关(二):跨站请求伪造(CSRF/XSRF)
简介 CSRF(Cross-site request forgery跨站请求伪造,也被称为“One Click Attack”或者Session Riding,通常缩写为CSRF或者XSRF,是一种对 ...
- java从基础知识(十)java多线程(下)
首先介绍可见性.原子性.有序性.重排序这几个概念 原子性:即一个操作或多个操作要么全部执行并且执行的过程不会被任何因素打断,要么都不执行. 可见性:一个线程对共享变量值的修改,能够及时地被其它线程看到 ...
- Device Tree(二):基本概念
转自:http://www.wowotech.net/linux_kenrel/dt_basic_concept.html 一.前言 一些背景知识(例如:为何要引入Device Tree,这个机制是用 ...
- CC2530使用串口下载(SBL)
工作环境: WIN7 64位 IAR 版本: 8.10.3 (8.10.3.10338) ZStack-CC2530-2.3.1-1.4.0协议栈,下载地址:http://download.csdn. ...
- Google Map API V3开发(6) 代码
Google Map API V3开发(1) Google Map API V3开发(2) Google Map API V3开发(3) Google Map API V3开发(4) Google M ...
- (三)内存 SDRAM 驱动实验 (杨铸 130 页)(勉强能懂个大概)
SDRAM 芯片讲解: 地址: 行地址 (A0-A12) 列地址 (A0-A8) 片选信号(BA0 BA1)(L-BANK)(因为SDRAM有 4片) 两片SDRAM 连线唯一区别在 UDQM ...
- LTE 测试文档(翻译)
Testing Documentation 翻译 (如有不当的地方,欢迎指正!) 1 概述 为了测试和验证 ns-3 LTE 模块,文档提供了几个 test suites (集成在 ns- ...
随机推荐
- numpy库:常用基本
numpy 本文主要列出numpy模块常用方法 大部分内容来源于网络,而后经过自己的一点思考和总结,如果有侵权,请联系我 我是一名初学者,有哪些地方有错误请留言,我会及时更改的 创建矩阵(采用ndar ...
- android的编译和运行过程深入分析
android的编译和运行过程深入分析 作者: 字体:[增加 减小] 类型:转载 首先来看一下使用Java语言编写的Android应用程序从源码到安装包的整个过程,此过程对了解android的编译和运 ...
- c#以文件流的形式输出xml(可以解决内存溢出)-XmlTextWriter
1.XmlTextWriter 表示提供快速.非缓存.只进方法的编写器,该方法生成包含 XML 数据(这些数据符合 W3C 可扩展标记语言 (XML) 1.0 和“XML 中的命名空间”建议)的流或文 ...
- 开心菜鸟系列学习笔记------javascript(4)
一.全局上下文中的变量对象: 1)全局对象(Global object) 是在进入任何执行上下文之前就已经创建了的对象:这个对象只存在一份,它的属性在程序中任何地方都可以访问,全局对象的 ...
- Qt编程之QImage类小结
最近用Qt做图像处理,以下references是需要用到的 references: http://blog.csdn.net/lyc_daniel/article/details/9193881 ht ...
- bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝
Description Farmer John has returned to the County Fair so he can attend the special events (concert ...
- 数字图像处理之sobel边缘检测
在前两部文章介绍了几种边缘检测算法,和位图的内存结构.如果对前两篇文章已经理解透彻 了,那么本文将带你进入数字图像处理的世界. 本文通过C代码实现基本的sobel边缘检测,包括8个方向和垂直方向: 代 ...
- ubuntu查看硬件信息
1,外部探针probe sudo apt-get install hwinfo 执行hwinfo获取系统信息 --short
- hdu2208之搜索
唉,可爱的小朋友 Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- javac命令详解(下)
摘自http://blog.csdn.net/hudashi/article/details/7058999 javac命令详解(下) -ver ...