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 _ ...
随机推荐
- FaceBook开源库Fresco
讨论学习使用 关于 Fresco Fresco 是一个强大的图片载入组件. Fresco 中设计有一个叫做 image pipeline 的模块.它负责从网络.从本地文件系统.本地资源载入图片. 为了 ...
- [BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)
Task schedule Problem Description 有一台机器,而且给你这台机器的工作表.工作表上有n个任务,机器在ti时间运行第i个任务,1秒就可以完毕1个任务. 有m个询问,每一个 ...
- JAVA 学习 IDEA安装及破解
1.到官网下载安装包 网址:https://www.jetbrains.com/idea/download/#section=windows 选择 “”Ultimate “”这个版本点击“Downl ...
- C/C++生成可执行文件过程
编译的概念:编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序.编译的 ...
- Codeforces Beta Round #96 (Div. 1) C. Logo Turtle DP
C. Logo Turtle A lot of people associate Logo programming language with turtle graphics. In this c ...
- 【codevs2011】【LNOI2013】最小距离之和
floyed水题 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstr ...
- 中国剩余定理模板&俄罗斯乘法
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b){d=a;x=1LL;y=0LL;} else {ex_gcd(b,a%b,d, ...
- web filter用spring注入对象
tomcat容器初始化顺序监听器–>过滤器–>servlet,因此springMVCservlet初始化之前,过滤器就已经初始化过了,如果在过滤器中需要注入spring容器管理的bean是 ...
- redis.exceptions.ConnectionError: Error 10061 connecting to 127.0.0.1:6379. 由于目标计算机积极拒绝,无法连接
redis.exceptions.ConnectionError: Error 10061 connecting to 127.0.0.1:6379. 由于目标计算机积极拒绝,无法连接 是由于没有 ...
- J20170616-hm
所以(ゆえん) 理由,原因,来由