[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 题目大意:根据储钱罐的重量,求出里面钱最少有多少.给定储钱罐的初始重量,装硬币后重量,和每个对应 ...
随机推荐
- select跳转
<select onchange="window.open(this.options[this.selectedIndex].value)"><option> ...
- Java中的定时器Timer
java.util.Timer是一个实用工具类,该类用来调度一个线程,使线程可以在将来某一时刻开始执行. Java的Timer类可以调度一个线程运行一次,或定期运行. java.util.TimerT ...
- 如何增加swap 大小
第一步:(这里增加2G) [root@kmdbrac1 /]# mkdir swap #创建一个文件夹,存放交换空间文件 [root@kmdbrac1 /]# cd swap # ...
- C#与JAVA平台RSA算法交互示例
很久以前的文章中,演示了如何对于.net和win32下面的delphi的RSA互操作性的实现,对于C#和JAVA之前的RSA加密解密也是很简单的,一般都采用了标准的规范,所以在互操作性方面是很方便的. ...
- 01TCP/IP基础
ISO/OSI参考模型: OSI(open system interconnection)开放系统互联模型是由ISO(International Organization for Standardiz ...
- phpstorm laravel单元测试 配置
laravel中集成了单元测试工具phpunit可以在项目的根目录下进行使用,命令是:phpunti ./tests/单元测试文件名称.在phpstorm中使用phpunit需要做一些配置,指定com ...
- jQuery实现表单验证
表单是网页的一个重要组成部分.本节做一个简单的表单提交网页然后利用jQuery实现表单的验证.后续的表单完善以及功能的完善会在以后的博客中给出. 效果图: 代码: <!DOCTYPE html ...
- 【转】Java集合框架综述
文章目录 1. 集合框架(collections framework) 2. 设计理念 3. 两大基类Collection与Map 3.1. Collection 3.2. Map 4. 集合的实现( ...
- iwpriv
AuthMode {OPEN,SHARED,WEPAUTO,WPAPSK,WPA2PSK,WPANONE} ::Set Authentication Mode EncrypTy ...
- 71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...