hdoj-1114 (背包dp)
题目链接
题意:已知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)的更多相关文章
- HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)
HDOJ(HDU).1114 Piggy-Bank (DP 完全背包) 题意分析 裸的完全背包 代码总览 #include <iostream> #include <cstdio&g ...
- 背包DP HDOJ 5410 CRB and His Birthday
题目传送门 题意:有n个商店,有m金钱,一个商店买x件商品需要x*w[i]的金钱,得到a[i] * x + b[i]件商品(x > 0),问最多能买到多少件商品 01背包+完全背包:首先x == ...
- 背包dp整理
01背包 动态规划是一种高效的算法.在数学和计算机科学中,是一种将复杂问题的分成多个简单的小问题思想 ---- 分而治之.因此我们使用动态规划的时候,原问题必须是重叠的子问题.运用动态规划设计的算法比 ...
- hdu 5534 Partial Tree 背包DP
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- 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 ...
- 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/ ...
- noj [1479] How many (01背包||DP||DFS)
http://ac.nbutoj.com/Problem/view.xhtml?id=1479 [1479] How many 时间限制: 1000 ms 内存限制: 65535 K 问题描述 The ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- BZOJ 1004: [HNOI2008]Cards( 置换群 + burnside引理 + 背包dp + 乘法逆元 )
题意保证了是一个置换群. 根据burnside引理, 答案为Σc(f) / (M+1). c(f)表示置换f的不动点数, 而题目限制了颜色的数量, 所以还得满足题目, 用背包dp来计算.dp(x,i, ...
- G - Surf Gym - 100819S -逆向背包DP
G - Surf Gym - 100819S 思路 :有点类似 逆向背包DP , 因为这些事件发生后是对后面的时间有影响. 所以,我们 进行逆向DP,具体 见代码实现. #include<bit ...
随机推荐
- vsftpd更新和修改版本号教程
1.rpm包更新 类似以下更新即可 rpm -Uvh vsftpd--.el6.x86_64.rpm 2.源码更新 不懂为什么对于新版本可能只有源码包而没有rpm等包,如此只能以源码更新了. .tar ...
- 【SQL】group by 及 having
Group By 分组汇总 HAVING:给分组设置条件 1.概述 “Group By”从字面意义上理解就是根据“By”指定的规则对数据进行分组,所谓的分组就是将一个“数据集”划分成若干个“小区域”, ...
- mongodb细节
MongoDB中数值型默认为Double,可以使用NumberInt()函数及NumberLong()函数分别指定某个字段为整型和长整型.
- learning scala write to file
scala 写文件功能: scala> import java.io.PrintWriterimport java.io.PrintWriter scala> val outputFile ...
- js图片时间和倒计时
图片时间原理 原理:使用定时器每秒获取时间,获取时间的时,分,秒,组成一个6位数的字符串,然后用charAt,截取出对应的字符,图片命名和数字相对应就ok拉 倒计时原理 原 ...
- bzoj3976
题解: 先跑一下Sa 然后再用kmp匹配一下哪一些位置不行 然后二分答案 代码: #include<bits/stdc++.h> ; using namespace std; int t[ ...
- [整理]Kadane算法
仅能操作一次时,需每次观察是否有为负情况置零.多次操作时,仅需判断是否后者大于前者. leetcode 53.121.122 [代码] class Solution { public int maxS ...
- Cracking The Coding Interview4.8
//You are given a binary tree in which each node contains a value. Design an algorithm to print all ...
- jquery 将一组元素转换成数组
HTML 代码: <p><b>Values: </b></p> <form> <input type="text" ...
- IIC协议解释(转)
IIC协议解释 推荐资源: http://m.elecfans.com/article/574049.html and https://blog.csdn.net/firefl ...