题意:一堆食物,有价值、空间、数量三种属性,一些卡车,有空间,价格,数量三种属性。求最少的钱(不超过50000)买卡车装下价值大于等于给定价值的食物,食物可以拆开来放

思路:这题的关键是给定的条件:食物可以拆开来放。这个条件使得卡车和食物可以分开考虑,然后通过空间这个属性联系在一起。做两遍多重背包即可。

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>
using namespace std; #define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a)) typedef long long ll;
typedef pair<int, int> pii; namespace Debug {
void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<" ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
}
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
/* -------------------------------------------------------------------------------- */ int dp[]; void zeroPack_min(int V, int v, int w) {
for (int i = V; i >= v; i --) {
umin(dp[i], dp[i - v] + w);
}
}
void zeroPack_max(int V, int v, int w) {
for (int i = V; i >= v; i --) {
umax(dp[i], dp[i - v] + w);
}
}
void MultiPack(int V, int v, int w, int remain, bool id) {
if (!remain) return;
int num = ;
while (remain) {
if (!id) zeroPack_min(V, v * num, w * num);
else zeroPack_max(V, v * num, w * num);
remain -= num;
num <<= ;
umin(num, remain);
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int T, n, m, p, v, w, c;
cin >> T;
while (T --) {
cin >> n >> m >> p;
fillchar(dp, 0x3f);
dp[] = ;
for (int i = ; i < n; i ++) {
scanf("%d%d%d", &v, &w, &c);
MultiPack(p + , v, w, c, );
}
int place = 0x3f3f3f3f;
for (int i = p; i <= p + ; i ++) umin(place, dp[i]);
fillchar(dp, );
for (int i = ; i < m; i ++) {
scanf("%d%d%d", &w, &v, &c);
MultiPack(, v, w, c, );
}
int ans = -;
for (int i = ; i <= ; i ++) {
if (dp[i] >= place) {
ans = i;
break;
}
}
if (~ans) cout << ans << endl;
else puts("TAT");
}
}

[hdu5445 Food Problem]多重背包的更多相关文章

  1. hdu 5445 Food Problem 多重背包

    Food Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  2. HDU 5445——Food Problem——————【多重背包】

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

  3. [HDOJ5445]Food Problem(优先队列优化多重背包)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:多重背包 分析:f[i][j]=max(f[i-1][j-k*w[i]]+k*v[i]) 将j ...

  4. HDU 5445 Food Problem(多重背包+二进制优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...

  5. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  6. (多重背包+记录路径)Charlie's Change (poj 1787)

    http://poj.org/problem?id=1787   描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...

  7. 单调队列优化DP,多重背包

    单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn ...

  8. HDU-2844 Coins(多重背包)

    Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...

  9. hdu 2191 多重背包 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

    http://acm.hdu.edu.cn/showproblem.php?pid=2191 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...

随机推荐

  1. mysql datetime类型 按格式在页面输出

    mysql datetime类型对应java Date类型   java.util.Date类型会显示时间戳 java.sql.Date 只显示年月日不显示时分秒 只需要重写get方法 就能按格式输出 ...

  2. 参数化parameterized

    pip install parameterized 注意:之前的nose-parameterized已经更新为parameterized库了 模块下测试方法直接使用parameterized impo ...

  3. [linux][MongoDB] mongodb学习(二):命令使用数据库

    使用数据库 # 查看数据库 > show dbs admin 0.000GB local 0.000GB # 查看表(集合) > show tables # 删除集合 > db.us ...

  4. Redis的三大问题

    一般我们对缓存读操作的时候有这么一个固定的套路: 如果我们的数据在缓存里边有,那么就直接取缓存的. 如果缓存里没有我们想要的数据,我们会先去查询数据库,然后将数据库查出来的数据写到缓存中. 最后将数据 ...

  5. TensorFlow的图像NCHW与NHWC

    import tensorflow as tf x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] with tf.Session() as sess: a = t ...

  6. Java 反射 -- 获取泛型类型

    先写一个类: public class Demo03 { public void test01(Map<String, User> map, List<User> list) ...

  7. JasperReports入门教程(二):中文打印

    JasperReports入门教程(二):中文打印 背景 在上一篇中我们介绍了JasperReport的基本入门,也展示了一个报表.但是我们的示例都是使用的英文,如果我们把需要打印的数据改为中文会怎么 ...

  8. 开发一款图片压缩工具(三):使用 click 实现命令行

    上一篇实现了图片的压缩函数.现在如果需要对图片进行压缩,可以调用实现的函数进行压缩: pngquant_compress('elephant.png', force=True, quality=20) ...

  9. 十分钟通过一个实际问题,真正教会大家如何解决Bug

    前言 这篇文章从实际问题 -> 问题解决步骤 -> 问题解决思路,帮助大家能够明白如何在程序中发现问题,定位问题,解决问题.并真正理解那些问题解决思路. 首先说说这个实际问题是什么,又是怎 ...

  10. Deepin15.11-mysql5.7安装与配置

    目录 1.卸载 2.换源 3.安装mysql-5.7并修改密码 4.修改mysql中字符编码 deepin系统中,默认的系统源,使用apt-get install mysql-server会自动拉取m ...