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]. 每 ...
随机推荐
- python 的异常及其处理
Python 异常处理 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理: 本站Python教程会具体介绍. 断言 ...
- CentOS最大文件描述符限制更改
系统级的限制:/proc/sys/fs/file-max中设定了系统最大能打开的文件数. 查看该值可以用如下方式: [root@#panda ~]# cat /proc/sys/fs/file-max ...
- [转]how to split the ng-repeat data with three columns using bootstrap
本文转自:http://stackoverflow.com/questions/21644493/how-to-split-the-ng-repeat-data-with-three-columns- ...
- 有评论就是我最大的动力~MySQL基础篇完结(存储引擎和图形化管理工具)
hi 今天登上来,发现竟然有了3个评论~~加油吧! 这周的计划其实远远没有达到,然后下周还有一大堆事情...那么...周末好好玩吧~ 今天试图完结MySQL的基础篇知识,小白变为大白? 1.MySQL ...
- Machine Learning Algorithms Study Notes(2)--Supervised Learning
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- leetcode-Combinations 复习复习排列组合
Combinations 题意: 根据给定的n和k,生成从1到n范围内长度为k的排列组合 示例: n=4 k=2 [[1, 2], [1, 3], [1, 4], [2, 1], [2, 3], [2 ...
- 在Docker中运行web应用
启动一个简单的web 应用 使用社区提供的模板,启动一个简单的web应用,熟悉下各种Docker命令的使用: # docker run -d -P training/webapp python app ...
- AC日记——石头剪子布 openjudge 1.7 04
04:石头剪子布 总时间限制: 1000ms 内存限制: 65536kB 描述 石头剪子布,是一种猜拳游戏.起源于中国,然后传到日本.朝鲜等地,随着亚欧贸易的不断发展它传到了欧洲,到了近现代逐渐风 ...
- childNodes的兼容性问题
元素.childNodes:只读 属性 子节点列表集合 标准浏览器下:包含文本和元素类型节点,也会包含非法嵌套的子节点 非标准浏览器下:只包含元素类型节点,ie7下不会包含非法嵌套的子节点 child ...
- javascript动态创建script标签,加载完成后调用回调
代码如下: var head = document.getElementsByTagName('head')[0]; var script = document.createElement('scri ...