怒刷DP之 HDU 1114
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2015-09-06)
Description
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
Output
Sample Input
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 100.
This is impossible.
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <climits>
using namespace std; const int SIZE = ,INF = 0x7ffffff;
long long DP[SIZE];
long long W[SIZE];
struct Node
{
int val,weight;
}S[]; int main(void)
{
int t,first,last,all,n; scanf("%d",&t);
while(t --)
{
scanf("%d%d%d",&first,&last,&n);
all = last - first;
for(int i = ;i <= n;i ++)
scanf("%d%d",&S[i].val,&S[i].weight); fill(DP,DP + SIZE,INF);
DP[] = ;
for(int i = ;i <= n;i ++)
for(int v = S[i].weight;v <= all;v ++)
DP[v] = min(DP[v],DP[v - S[i].weight] + S[i].val); if(DP[all] == INF)
puts("This is impossible.");
else
printf("The minimum amount of money in the piggy-bank is %lld.\n",DP[all]);
} return ;
}
怒刷DP之 HDU 1114的更多相关文章
- 怒刷DP之 HDU 1257
		最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ... 
- 怒刷DP之 HDU 1160
		FatMouse's Speed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ... 
- 怒刷DP之 HDU 1260
		Tickets Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Stat ... 
- 怒刷DP之 HDU 1176
		免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ... 
- 怒刷DP之 HDU 1087
		Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64 ... 
- 怒刷DP之 HDU 1069
		Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ... 
- 怒刷DP之 HDU 1024
		Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ... 
- 怒刷DP之 HDU 1029
		Ignatius and the Princess IV Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d &a ... 
- 【DP】HDU 1114
		HDU 1144 Piggy-Bank 题意:有这么个存钱罐,给你空的时候重量和满的时候的重量,再给你N中类型的硬币(给出N种硬币总数量和总重量,可多次使用),问你怎样恰好填满存钱罐,而让填入的硬币数 ... 
随机推荐
- 关于html和body高度 登录页面登录框永远保持在页面垂直水平居中位置
			HTML CSS 解说,水平居中就不用多说了,给div.login_wrap设置个宽度,然后margin:0 auto;就可以做到.但是这里这样做,这里使用了两层div 外层使用margin:0 au ... 
- WPF中的DependencyProperty存储方式详解
			前言 接触WPF有一段时间了,之前虽然也经常使用,但是对于DependencyProperty一直处于一知半解的状态.今天花了整整一下午将这个概念梳理了一下,自觉对这个概念有了较为清晰的认识,之前很多 ... 
- Oracle的体系结构
			前言 这个章节主要想说的是Oracle的体系结构,这个也是理论强些.还有一些比较理论的知识点(比如表空间啊),就暂时先不写了,下一章节开始进入Oracle的操作阶段,比如表的查询啊.插入以及重点是和S ... 
- 检测一个DOM对象是否为空
			我们时常要检测一个DOM对象是否为空. var $jObject = $('#btn'); alert($jObject ); 我们会发现,$jObject 永远不会为空.为什么呢?$ 方法查找对象, ... 
- RESTful Webservice (一) 概念
			Representational State Transfer(表述性状态转移) RSET是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩 ... 
- boost::token_compress_on
			对于场景:string s = "123456",用"3","4"切分,默认情况下(boost::token_compress_off),切 ... 
- 制作Windows的ico图标
			也不知道这个方法是不是最好的,有时间再查看其它方法 首先设计出图标,png格式即可. 使用一款软件 IconWorkshop 下载了一个试用版,临时制作够用了 制作步骤如下: 1.打开png图片 2. ... 
- BZOJ 1295: [SCOI2009]最长距离 spfa
			1295: [SCOI2009]最长距离 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1295 Description windy有一块 ... 
- android标题栏(titlebar)显示进度条
			在后台线程中执行各种操作(网络连接.大数据存储)的时候,我们希望让客户能看到后台有操作在进行,那么既能有效的提示用户,又不占用当前操作空间,最好的方法就是在标题栏有个进度条. [代码] [Java]代 ... 
- [Angular2 Form] Display Validation and Error Messaging in Angular 2
			Angular 2’s ngModel provides error objects for each of the built-in input validators. You can access ... 
