题意:

已知储蓄罐满时的质量f以及空时质量e,

有n种硬币,每种硬币的价值为p,质量为w,

求该储蓄罐中的最少有多少钱?

思路:

完全背包思想,问题是在一个重量下的最小价值

那么只要变一下符号就好了?

//#include <bits/stdc++.h>
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
using namespace std; typedef __int64 LL; const int INF=0x3f3f3f3f;
const int N=1e4+10;
int w[550],v[550];
int dp[N];
int W;
int x,y;
int n; int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&x,&y);
W=y-x;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&v[i],&w[i]);
memset(dp,INF,sizeof(dp));
dp[0]=0;
for(int i=0;i<n;i++)
for(int j=w[i];j<=W;j++)
dp[j]=min(dp[j-w[i]]+v[i],dp[j]);
if(dp[W]==INF)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[W]);
}
return 0;
}

POJ 1384【完全背包】的更多相关文章

  1. POJ 1384 Piggy-Bank 背包DP

    所谓的全然背包,就是说物品没有限制数量的. 怎么起个这么intimidating(吓人)的名字? 事实上和一般01背包没多少差别,只是数量能够无穷大,那么就能够利用一个物品累加到总容量结尾就能够了. ...

  2. poj 1384完全背包

    题意:给出猪罐子的空质量和满质量,和n个硬币的价值和质量,求猪罐子刚好塞满的的最小价值. 思路:选择硬币,完全背包问题,塞满==初始化为无穷,求最小价值,min. 代码: #include<io ...

  3. poj 1384 Piggy-Bank(全然背包)

    http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...

  4. POJ 1384 POJ 1384 Piggy-Bank(全然背包)

    链接:http://poj.org/problem?id=1384 Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Submissio ...

  5. 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 ...

  6. POJ 1384 Piggy-Bank(完全背包)

    Description Before ACM can do anything, a budget must be prepared and the necessary financial suppor ...

  7. POJ 1384 Piggy-Bank (完全背包)

    Piggy-Bank 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/F Description Before ACM can d ...

  8. poj 1384 Piggy-Bank(完全背包)

    Piggy-Bank Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10830   Accepted: 5275 Descr ...

  9. POJ 1384 Piggy-Bank【完全背包】+【恰好完全装满】(可达性DP)

    题目链接:https://vjudge.net/contest/217847#problem/A 题目大意:   现在有n种硬币,每种硬币有特定的重量cost[i] 克和它对应的价值val[i]. 每 ...

随机推荐

  1. ngnix

    nginx的平滑重启 博客分类: nginx nginx平滑重启  在研发过程中,修改nginx的配置文件nginx.conf是很平常的事,需要重启nginx.如果我们直接reload是有一定风险的, ...

  2. 关于文件与文件系统的压缩与打包命令-Linux(笔记)

    1.gzip : 压缩命令 gzip [-cdtv#] 文件名称 (后缀为.gz) -c :将压缩的数据输出到屏幕上,可通过数据流重定向处理 -d : 解压缩的參数 -v : 能够显示源文件/压缩文件 ...

  3. PHP生成excel(2)

    现在数据库有一组数据,就是按照年级的分类的学生分数,如何按照年级分类导出到excel表中 1.数据库配置文件config.php <?php $config = array( 'host'=&g ...

  4. Mesa (computer graphics)

    http://en.wikipedia.org/wiki/Mesa_(computer_graphics) Mesa (computer graphics) From Wikipedia, the f ...

  5. DBExecutor android 数据库框架

    https://github.com/eltld/DBExecutor android 数据库框架,sqlite database

  6. 翻译:A Tutorial on the Device Tree (Zynq) -- Part II

    A Tutorial on the Device Tree (Zynq) -- Part II 设备树结构 Zynq的设备树如下: /dts-v1/; / { #address-cells = < ...

  7. android5.0(Lollipop) BLE Peripheral牛刀小试

    转载请表明作者:http://blog.csdn.net/lansefeiyang08/article/details/46468743 知道Android L对蓝牙对了一些改进.包含加入A2dp s ...

  8. python day 13 生成器 以及 推导式

    1.生成器的本质是迭代器 2.生成器函数 def  fn() 函数体 yield fn() g = fn() 此时这个g就是生成器 所以g 是可迭代的 g._ _next_ _ 每执行一次_ _nex ...

  9. Mac使用小结

    1.修改pip的镜像地址及更新pip https://www.cnblogs.com/techroad4ca/p/5922389.html 2.更新python的库,比如更新six sudo pip ...

  10. 在Qt Creator中为Qt工程添加资源

    1.右键单击工程 -> Add New ... -> Qt -> Qt Resource File -> Choose... -> Name: -> Next -& ...