HDU_1114_piggy-bank
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
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
Sample Output
题解:完全背包
代码:
#include<stdio.h>
#define MAX 5000000
int min(int a,int b)
{
return a<b?a:b;
}
int dp[MAX];
int main()
{
int t,e,f,n,p[],w[],v;
int i,j;
scanf("%d",&t);
while(t--)
{
dp[]=;
for(i=;i<MAX;i++)
dp[i]=MAX;
scanf("%d%d",&e,&f);
v=f-e;
scanf("%d",&n);
for(i=;i<n;i++)
scanf("%d%d",&p[i],&w[i]);
for(i=;i<n;i++)
for(j=w[i];j<=v;j++) //此j循环与01背包循序相反
dp[j]=min(dp[j],dp[j-w[i]]+p[i]);
if(dp[v]==MAX)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[v]);
}
return ;
} 下图为简单的模拟dp数组的元素及其更新

HDU_1114_piggy-bank的更多相关文章
- 以bank account 数据为例,认识elasticsearch query 和 filter
Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...
- bzoj1531: [POI2005]Bank notes
Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...
- DSY1531*Bank notes
Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...
- 银行卡BIN: Bank Identification Number
What is a 'Bank Identification Number - BIN'A bank identification number (BIN) is the initial four t ...
- java异常处理:建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount),当取款的数额大于存款时,抛出InsufficientFundsException,取款数额为负数,抛出NagativeFundsException,如new Bank(100),
建立exception包,建立Bank类,类中有变量double balance表示存款,Bank类的构造方法能增加存款,Bank类中有取款的发方法withDrawal(double dAmount ...
- 神奇的Bank系统之旅哦
奋斗不能等待,我们不能等到垂暮之年再去“全力以赴”.让我们从现在开始,为理想而努力,为人生而拼搏.精诚所至,金石为开,相信奋斗会让我们的青春之花绽放得更加绚烂,让我们的人生之路走下来不留遗憾. ...
- CUDA中Bank conflict冲突
转自:http://blog.csdn.net/smsmn/article/details/6336060 其实这两天一直不知道什么叫bank conflict冲突,这两天因为要看那个矩阵转置优化的问 ...
- Bank,我只是来完成作业的
写这个Bank我需要有:开户,取款,存款,转账,查询余额,退出功能. 这样我需要有两个类:Bank,User.一个Main入口. 先看这个User,他定义了各个需要的属性(字段)和字段的属性(虽然在这 ...
- 1531: [POI2005]Bank notes二进制优化(c++)
Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...
- Bank homework 10 2016 4 25
#include<iostream>#include<string>using namespace std;class Bank { public: Bank(string _ ...
随机推荐
- Memento - 备忘录模式
定义 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态. 案例 比方如今有一个画图系统,我们在Viewer里面画了一些图形,可是在绘 ...
- powerShell赋权限
1.给网站赋权限 Set-SPUser –Identity “用户名” –AddPermissionLevel “参与讨论” –web “http://url” 2.给列表赋权限 $web = Get ...
- Linux系统编程_6_进程环境(C程序典型的存储空间)
1.八种结束Linux进程的方法: 五种正常终止方式: main函数返回: 调用exit: 调用_exit或_Exit 最后一个线程从其启动例程返回 最后一个线程调用pthread_exit 三种异常 ...
- python 【目录】
python[目录] python[第一篇]初识python python[第二篇]python基本数据类型 python[第三篇]python函数基础
- ios33--线程安全
// // ViewController.m // 05-掌握-线程安全 // // 多线程下载文件:每个线程下的部分可能是交错的,到时候就拼接不了.除非每个线程下载的不是交错的,而是从头到尾依次分开 ...
- 以太网接口TCP/IP协议介绍,说的很容易懂了
以太网接口TCP/IP协议介绍,说的很容易懂了 TCP/IP协议,或称为TCP/IP协议栈,或互联网协议系列. TCP/IP协议栈(按TCP/IP参考模型划分) 应用层 FTP SMTP HTT ...
- XML解析方式汇总
XML解析方式汇总 分类: XML2011-08-23 19:19 167人阅读 评论(0) 收藏 举报 xmlstringexceptionattributesclassiterator DOM解析 ...
- 关于flask的错误:ImportError: cannot import name 'Flask'
刚开始接触flask,新创建后不能运行,报错如下图: 导致该错误有两种可能,没安装flask:文件名为flask. 可尝试如下两种方法解决: 方法一:若没安装过flask,则进入cmd,输入pip i ...
- Java 泛型 四 基本用法与类型擦除
简介 Java 在 1.5 引入了泛型机制,泛型本质是参数化类型,也就是说变量的类型是一个参数,在使用时再指定为具体类型.泛型可以用于类.接口.方法,通过使用泛型可以使代码更简单.安全.然而 Java ...
- poj 1201 Intervals【差分约束+spfa】
设s为前缀和,首先显然的条件是\[ s_{bi}-s_{ai-1}>=c \],然后隐含的是\[ s_i-s_{i-1}>=0 s_i-s_{i-1}<=1 \] 然后根据差分约束, ...