POJ 1384【完全背包】
2024-10-21 06:35:15
题意:
已知储蓄罐满时的质量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;
}
最新文章
- [翻译] ORMLite document -- How to Use Part (二)
- Linux No volume control GStreamer plugins and/or devices found
- android:TableLayout表格布局详解
- python中的not具体使用及意思
- mvc 4 razor语法讲解和使用
- php 和mysql httpd 简单网页的搭建
- ciancd开源
- D. Array GCD
- UML: 对象图
- BZOJ 1061 志愿者招募(最小费用最大流)
- Photoshop图层混合模式计算公式大全(转)
- 我的docker 使用笔记
- maven常见问题汇总
- ubuntu 14.04 GDAL
- spring异常处理
- 【视频编解码&#183;学习笔记】3. H.264视频编解码工程JM的下载与编解码
- 【Java编程思想笔记】-集合2
- 【Python】sql-内连接,左连接,右连接,union
- 机器学习与Tensorflow(1)——机器学习基本概念、tensorflow实现简单线性回归
- Winter Storm Warning
热门文章
- 创建git仓库及简单操作命令
- SD卡读写之FileNotFoundException: /storage/emulated/0object.txt: open failed: ENOENT (No such file or dir
- HDU 3820 Golden Eggs( 最小割 奇特建图)经典
- C# - CLR
- actionbar tab 字体大小设置
- sql注入攻防 以php+mysql为例
- 【Java】Java代码经典错误清单
- MUI-折叠面板效果accordion
- HDU 6061 RXD and functions NTT
- javascript常用事件及方法