poj-1384 Piggy-Bank
poj-1384 Piggy-Bank 地址:http://poj.org/problem?id=1384
题意:
知道盒子里面的物体的总重量,得到每一种硬币的价格和重量,求最少钱构成盒子物体总重量的钱的数量。
分析:
典型的不限重背包问题。当然维度也是在可以接受的范围, 直接设置dp数组进行min操作。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
using namespace std;
const int maxn = ;
const int max_val = ; int E,F, n, dp[max_val+]; struct Node{
int p,w;
}nd[maxn]; int cmp(const void* a, const void* b){
Node* aa = (Node *)a;
Node* bb = (Node *)b;
return (bb->w*1.0)/(bb->p*1.0) - (aa->w*1.0)/(aa->p*1.0);
} int main(){
freopen("in.txt", "r", stdin); int test_num, i, j;
scanf("%d", &test_num);
while(test_num--){
scanf("%d %d", &E, &F);
scanf("%d", &n);
for(i=; i<n; i++){
scanf("%d %d", &nd[i].p, &nd[i].w);
}
memset(dp, 0x3f3f3f3f, sizeof(dp));
dp[] = ;
for(i=; i<n; i++){
for(j=nd[i].w; j<=(F-E); j++){
if(dp[j - nd[i].w] != 0x3f3f3f3f ){
dp[j] = min(dp[j-nd[i].w]+nd[i].p, dp[j]);
}
}
}
if(dp[F-E] == 0x3f3f3f3f){
printf("This is impossible.\n");
}else{
printf("The minimum amount of money in the piggy-bank is %d.\n", dp[F-E]);
}
}
return ;
}
poj-1384 Piggy-Bank的更多相关文章
- poj 1384 Piggy-Bank(全然背包)
http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1384 POJ 1384 Piggy-Bank(全然背包)
链接:http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...
- POJ 1384 Piggy-Bank (ZOJ 2014 Piggy-Bank) 完全背包
POJ :http://poj.org/problem?id=1384 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode ...
- POJ 1384 Intervals (区间差分约束,根据不等式建图,然后跑spfa)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others ...
- poj 1384 Piggy-Bank(完全背包)
Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10830 Accepted: 5275 Descr ...
- POJ 1384
求猜存钱罐中至少有多少钱.容易知道金币总的重量,接着背包. #include<cstdio> #include<iostream> using namespace std; # ...
- POJ 1384 Piggy-Bank 背包DP
所谓的全然背包,就是说物品没有限制数量的. 怎么起个这么intimidating(吓人)的名字? 事实上和一般01背包没多少差别,只是数量能够无穷大,那么就能够利用一个物品累加到总容量结尾就能够了. ...
- poj 1384完全背包
题意:给出猪罐子的空质量和满质量,和n个硬币的价值和质量,求猪罐子刚好塞满的的最小价值. 思路:选择硬币,完全背包问题,塞满==初始化为无穷,求最小价值,min. 代码: #include<io ...
- ACM Piggy Bank
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- POJ 1384 Piggy-Bank【完全背包】+【恰好完全装满】(可达性DP)
题目链接:https://vjudge.net/contest/217847#problem/A 题目大意: 现在有n种硬币,每种硬币有特定的重量cost[i] 克和它对应的价值val[i]. 每 ...
随机推荐
- shutdown
关机命令 $sudo shutdowm [-hrc] -h定时关机,以分钟为单位的计时,时间或now -h now立即关机 -h +2020分钟后关机 -h 12:0012点关机 -r now立即重启 ...
- org.eclipse.ui.menus扩展点学习
Eclipse菜单: menu:help?after=addtions menu:navigate?after=open.ext2 menu:window?after=newEditor menu:f ...
- 基于内容产品的MVP探索
王凯:凯叔讲故事的创始人 1.精益创业有以下3个过程: ——假设:价值假设和增长假设 ——认知:验证认知 ——行动:MVP(最小化可行产品) 2.互联网时代内容该如何定价: ——对于一家初创公司,最重 ...
- Unity arm64
ERROR ITMS-90086 ERROR ITMS-90086:"missing 64-bit support. beginning on february 1, 2015, new i ...
- Java写的斗地主游戏源码
源码下载在最后 我们的前年的课设要求做一个斗地主程序,当时正在愁如何做界面,当时刚好在学习C#,于是就用C#完成了这个程序.一方面,当时我C#功底还很差(其实现在也不怎么样),很多地方用了“笨办法”, ...
- [转帖]VS选中某个代码报错修补
如题,此问题,出现在xp sp3的情况比较多,至少在我常用的两台电脑上面是这样子的, 完整的安装了VS2010之后,在编写代码的时候,只要用鼠标拖选代码或者双击,选中某个代码,IDE就自动报错 重启 ...
- oracl中的集合操作符
1:union(并集) union连接两条sql语句,并且去除两条sql语句重复的记录 2.union all(并集) 接两句sql语句,两句sql语句的和不用去掉重复的记录. 3:inter ...
- [No00000A]计算机的存储单位
位 bit (比特)(Binary Digits):存放一位二进制数,即 0 或 1,最小的存储单位. 字节 byte:8个二进制[bit (比特)(Binary Digits)]位为一个字节(B), ...
- bzoj1787 [Ahoi2008]Meet 紧急集合
1787: [Ahoi2008]Meet 紧急集合 Time Limit: 20 Sec Memory Limit: 162 MB Submit: 2272 Solved: 1029 [Submi ...
- C#将JSON字符串对象序列化与反序列化
C#将对象序列化成JSON字符串 public string GetJsonString() { List<Product> products = new List<Product& ...