题目链接

  题意:已知n种coin的价值和体积  求装满容量为v背包的最小硬币价值

 #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int INF=0x3f3f3f3f;
int dp[][];//前i个元素将j装满的最小价值
int p[],w[];
int n,v;
int main ()
{
int T; scanf ("%d",&T);
while (T--) {
memset (dp,0x3f,sizeof(dp));
dp[][]=;
int v1,v2; scanf ("%d %d",&v1,&v2);
v=v2-v1;
scanf ("%d",&n);
for (int i=;i<=n;i++)
scanf ("%d %d",&p[i],&w[i]);
for (int i=;i<=n;i++)
for (int j=;j<=v;j++) {
dp[i][j]=dp[i-][j];
if (j>=w[i])
dp[i][j]=min (dp[i][j],dp[i][j-w[i]]+p[i]);
}
if (dp[n][v]==INF) printf("This is impossible.\n");
else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[n][v]);
}
return ;
}

hdoj-1114 (背包dp)的更多相关文章

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

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

  2. 背包DP HDOJ 5410 CRB and His Birthday

    题目传送门 题意:有n个商店,有m金钱,一个商店买x件商品需要x*w[i]的金钱,得到a[i] * x + b[i]件商品(x > 0),问最多能买到多少件商品 01背包+完全背包:首先x == ...

  3. 背包dp整理

    01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...

  4. hdu 5534 Partial Tree 背包DP

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  5. HDU 5501 The Highest Mark 背包dp

    The Highest Mark Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  6. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  7. noj [1479] How many (01背包||DP||DFS)

    http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...

  8. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  9. BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )

    题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...

  10. G - Surf Gym - 100819S -逆向背包DP

    G - Surf Gym - 100819S 思路 :有点类似 逆向背包DP , 因为这些事件发生后是对后面的时间有影响. 所以,我们 进行逆向DP,具体 见代码实现. #include<bit ...

随机推荐

  1. which/whereis/locate/find的区别

    which--在$PATH目录下查找文件 whereis--在预定目录下(whereis -l查看)查找文件 locate--在数据库中查找目录或文件 find--遍历目录查找文件 说明: 1.关于w ...

  2. Qt贴图实现地图标记效果

    #include "wgtmap.h" #include "ui_wgtmap.h" #include <QPainter> #define IMG ...

  3. Qt调用JS(二)

    转自:http://www.cnblogs.com/verstin/p/4908673.html <html> <script language="JavaScript&q ...

  4. react router @4 和 vue路由 详解(全)

    react router @4 和 vue路由 本文大纲: 1.vue路由基础和使用 2.react-router @4用法 3.什么是包容性路由?什么是排他性路由? 4.react路由有两个重要的属 ...

  5. shell 数值运算

    declare数值运算 linux默认变量类型为字符串 declare [+/-] [选项] 变量名 '-' 给变量设定类型属性 '+' 取消变量的类型属性 '-a' 将变量声明为数组型 '-i' 将 ...

  6. Linux command parted

    Linux command parted [Purpose]        Learning linux command parted to manipulate disk partitions   ...

  7. 跨域 jsonp 和 CORS 资料

    http://mp.weixin.qq.com/s/iAShnqvsOyV-Xd0Ft7Nl2Q HTML5安全:CORS(跨域资源共享)简介...ie67不要想了... http://www.cnb ...

  8. css3 居中(推荐弹性盒模型方式)

    参考  http://www.zhihu.com/question/20774514 http://caibaojian.com/demo/flexbox/align-items.html 例子:ht ...

  9. nginx入门示例(二)

    nginx使用域名访问 (Tip)      nginx目录解析 conf/nginx.conf   #主要的配置文件目录 html      #nginx的默认发布目录,部署完后 网站会在这个目录 ...

  10. .net core webapi 配置swagger调试界面

    一.创建一个.net core webapi的项目: 二.在nuget程序包管理器控制台输入  Install-Package Swashbuckle -version 6.0.0-beta902   ...