题意:

已知储蓄罐满时的质量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;
}

最新文章

  1. [翻译] ORMLite document -- How to Use Part (二)
  2. Linux No volume control GStreamer plugins and/or devices found
  3. android:TableLayout表格布局详解
  4. python中的not具体使用及意思
  5. mvc 4 razor语法讲解和使用
  6. php 和mysql httpd 简单网页的搭建
  7. ciancd开源
  8. D. Array GCD
  9. UML: 对象图
  10. BZOJ 1061 志愿者招募(最小费用最大流)
  11. Photoshop图层混合模式计算公式大全(转)
  12. 我的docker 使用笔记
  13. maven常见问题汇总
  14. ubuntu 14.04 GDAL
  15. spring异常处理
  16. 【视频编解码&#183;学习笔记】3. H.264视频编解码工程JM的下载与编解码
  17. 【Java编程思想笔记】-集合2
  18. 【Python】sql-内连接,左连接,右连接,union
  19. 机器学习与Tensorflow(1)——机器学习基本概念、tensorflow实现简单线性回归
  20. Winter Storm Warning

热门文章

  1. 创建git仓库及简单操作命令
  2. SD卡读写之FileNotFoundException: /storage/emulated/0object.txt: open failed: ENOENT (No such file or dir
  3. HDU 3820 Golden Eggs( 最小割 奇特建图)经典
  4. C# - CLR
  5. actionbar tab 字体大小设置
  6. sql注入攻防 以php+mysql为例
  7. 【Java】Java代码经典错误清单
  8. MUI-折叠面板效果accordion
  9. HDU 6061 RXD and functions NTT
  10. javascript常用事件及方法