[HDU 1114] Piggy-Bank (动态规划)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114
简单完全背包,不多说。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <iterator>
#include <vector>
using namespace std;
typedef long long LL; int T;
int E,F;
int dp[];
int p[],w[];
const int INF = ; int main(){
scanf("%d",&T);
while( T-- ){
scanf("%d%d",&E,&F);
F -= E;
int n;
scanf("%d",&n);
for(int i=;i<;i++) dp[i] = INF;
dp[] = ;
for(int i=;i<=n;i++) scanf("%d%d",&p[i],&w[i]);
for(int i=;i<=n;i++){
for(int j=w[i];j<=F;j++){
dp[j] = min(dp[j],dp[j-w[i]]+p[i]);
}
}
if( dp[F]!=INF )
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[F]);
else
puts("This is impossible.");
}
return ;
}
[HDU 1114] Piggy-Bank (动态规划)的更多相关文章
- HDU 1114 Piggy-Bank(动态规划、完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Piggy-Bank(HDU 1114)背包的一些基本变形
Piggy-Bank HDU 1114 初始化的细节问题: 因为要求恰好装满!! 所以初始化要注意: 初始化时除了F[0]为0,其它F[1..V]均设为−∞. 又这个题目是求最小价值: 则就是初始化 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- hdu 1114 dp动规 Piggy-Bank
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)
HDOJ(HDU).1114 Piggy-Bank (DP 完全背包) 题意分析 裸的完全背包 代码总览 #include <iostream> #include <cstdio&g ...
- HDU 1114 Piggy-Bank(一维背包)
题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm& ...
- HDU 1114 完全背包 HDU 2191 多重背包
HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...
- 动态规划:HDU 1114 Piggy-Bank
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- HDU 1114 Piggy-Bank(完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目大意:根据储钱罐的重量,求出里面钱最少有多少.给定储钱罐的初始重量,装硬币后重量,和每个对应 ...
随机推荐
- JS对日期时间的操作
代码: //判断是否超期(有效期开始超过一年后算已超期) function IsEffect(effectDate) { var val = ""; var currentDate ...
- Mac安装Appium
通过淘宝镜像安装 npm --registry http://registry.cnpmjs.org install -g appium 如果提示权限不够的话,需要加sudo,并输入对应密码 sudo ...
- js下的sleep实现
function sleep(d){ for(var t = Date.now();Date.now() - t <= d;); } sleep(5000); //当前方法暂停5秒
- css禁用鼠标点击事件
css禁用鼠标点击事件 .disabled { pointer-events: none; } <div class="main-container disabled"> ...
- PHP 生成指定大小随机图片
PHP 生成指定大小随机图片 <?php $image_width = 100; $image_height = 100; $image_str = ''; if (isset($_GET['w ...
- HackerRank "No Prefix Set"
Typical Trie usage. But please note that it could be any order of input strings. #include <algori ...
- python正则表达式的学习记录
match和findall的区别以及有括号和无括号的区别 strvar = "hello\n\nworld" find_re = re.compile("hello[.| ...
- [platform]linux platform device/driver(一)--Driver是如何找到对应的device
1.platform device是怎么"自动"关联到platform driver上的? 转向linux driver有些时间了,前段时间碰到个问题,在Linux kernel ...
- "XX cannot be resolved to a type "eclipse报错及解决说明
转自:http://zhaoningbo.iteye.com/blog/1137215 引言: eclipse新导入的项目经常可以看到“XX cannot be resolved to a type” ...
- 删除SQL server 实例
在网上找到下面几种方法,本人使用的是第一种,很实用. 1.删除 SQL Server 的特定实例若要删除 SQL Server 的某个特定实例,请按照以下步骤操作: 找到并删除%drive%:\\Pr ...