题目链接

  题意:已知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. 把旧系统迁移到.Net Core 2.0 日记 (12) --发布遇到的问题

    1. 开发时是在Mac+MySql, 尝试发布时是在SQL2005+Win 2008 (第一版) 在Startup.cs里,数据库连接要改,分页时netcore默认是用offset关键字分页, 如果用 ...

  2. 码云git使用四(分支的创建,使用和合并)

    我们在使用git的时候,一般都不是直接在主代码中开发, 通常我们做的操作是创建一个分支,我们在分支上开发,开发完毕,在提交到主代码中. 我们现在学习创建分支,合并分支. 1.首先我们下载到本地都是在主 ...

  3. Notes on Large-scale Video Classification with Convolutional Neural Networks

    Use bigger datasets for CNN in hope of better performance. A new data set for sports video classific ...

  4. dl简单模板,无pretraining过程

    layer_dimensions = [11 22 33 22 11]'; ld_size = size(layer_dimensions , 1); % what is deal [x rx dx ...

  5. 我眼中的Linux系统和红帽RHCE认证

    牛顿曾经说过“我不知道在别人看来,我是什么样的人:但在我自己看来,我不过就象是一个在海滨玩耍的小孩,为不时发现比寻常更为光滑的一块卵石或比寻常更为美丽的一片贝壳而沾沾自喜,而对于展现在我面前的浩瀚的真 ...

  6. day22 模块_1

    核能来袭--模块 1.简单了解模块 2.Collections 3.Time模块 4.functools 一.初识模块 其实之前写的每一个PY文件都是一个模块 还有一些我们一直在使用的模块  buil ...

  7. substr、substring和slice的区别

    substr(start,[length])表示从start位置开始取length个字符串:substring(start,end)表示从start,到end之间的字符串,包括start位置的字符但是 ...

  8. Linux U盘安装

    Ubuntu 15 U盘安装: 用UltraISO把iso文件写入到U盘中,选择hdd+模式. u盘启动后提示not a com32r image,先按tab键,然后输入live进入试用模式,然后再点 ...

  9. House Robber III

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  10. python造数

    做性能测试时,往往需要大量的参数化数据,比如注册. from random import Random def random_str(randomlength=8): str='' chars='01 ...