题目链接: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 (动态规划)的更多相关文章

  1. HDU 1114 Piggy-Bank(动态规划、完全背包)

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. Piggy-Bank(HDU 1114)背包的一些基本变形

    Piggy-Bank  HDU 1114 初始化的细节问题: 因为要求恰好装满!! 所以初始化要注意: 初始化时除了F[0]为0,其它F[1..V]均设为−∞. 又这个题目是求最小价值: 则就是初始化 ...

  3. 怒刷DP之 HDU 1114

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  4. hdu 1114 dp动规 Piggy-Bank

    Piggy-Bank Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

  5. HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)

    HDOJ(HDU).1114 Piggy-Bank (DP 完全背包) 题意分析 裸的完全背包 代码总览 #include <iostream> #include <cstdio&g ...

  6. HDU 1114 Piggy-Bank(一维背包)

    题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm& ...

  7. HDU 1114 完全背包 HDU 2191 多重背包

    HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...

  8. 动态规划:HDU 1114 Piggy-Bank

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

  9. HDU 1114 Piggy-Bank(完全背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114 题目大意:根据储钱罐的重量,求出里面钱最少有多少.给定储钱罐的初始重量,装硬币后重量,和每个对应 ...

随机推荐

  1. asp.net获取当前网址url的各种属性(文件名、参数、域名 等)的代码

    用 asp.net获取当前网页地址的一些信息. 设当前页完整地址是:http://www.jb51.net/aaa/bbb.aspx?id=5&name=kelli "http:// ...

  2. ios系统下,html5拍照上传的压缩处理

    http://gokercebeci.com/dev/canvasresize 通过canvas和base64的处理方式实现大尺寸照片的压缩和上传 介绍: https://github.com/zev ...

  3. IDEA快捷键大全

    IntelliJ Idea 常用快捷键列表 Ctrl+Shift + Enter,语句完成“!”,否定完成,输入表达式时按 “!”键Ctrl+E,最近的文件Ctrl+Shift+E,最近更改的文件Sh ...

  4. HTML之布局position理解

    HTML中的布局,一个比较难以理解的概念,就是position了,W3C上的解释,position有如下几种: 1. static,默认值,也就是在样式中不指定position 2. fixed 3. ...

  5. SPOJ #10657. LOGIC (riddle)

    1 line in Ruby(2.0), 36B: p (1..n=gets.to_i).reduce(:*)+2**n-n

  6. Python基础教程【读书笔记】 - 2016/7/31

    希望通过博客园持续的更新,分享和记录Python基础知识到高级应用的点点滴滴! 第十波:第10章  充电时刻 Python语言的核心非常强大,同时还提供了更多值得一试的工具.Python的标准安装包括 ...

  7. update openssl on redhat/centos

    $ openssl versionOpenSSL 1.0.1e-fips 11 Feb 2013 $ yum list |grep opensslopenssl.x86_64 1.0.1e-16.el ...

  8. Linux下nice/renice命令小结

    1. nice命令 内核根据进程的nice值决定进程需要多少处理器时间. nice值的取值范围是是: -20到20. 一个具有-20 的 nice 值的进程有很高的优先级. 一个 nice 值为 20 ...

  9. android学习笔记三

    GUI==>Graphics User Interface,图形用户界面. android UI 建立在View.ViewGroup基础上,采用组合器设计模式设计View和ViewGoup. V ...

  10. 二. log4j配置文件

    log4j的配置文件 # Output pattern : date [thread] priority category - message log4j.rootLogger=info,Consol ...