题意:一堆食物,有价值、空间、数量三种属性,一些卡车,有空间,价格,数量三种属性。求最少的钱(不超过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. 数据结构(C语言版)---栈

    1.栈:仅在表尾进行插入和删除操作的线性表.后进先出LIFO. 1)表尾端(允许插入和删除的一端)为栈顶,表头端(不允许插入和删除的一端)为栈底. 2)入栈:插入元素的操作.出栈:删除栈顶元素 3)栈 ...

  2. 5. class--extends

    ES5: function article(x,y){ this.x = x; this.y = y; } article.prototype.say = function() { return (t ...

  3. Mysql使用终端操作数据库

      使用终端操作数据库       1.如何查看有什么数据库?     show databases;        2.如何选择数据库?    use databasesName;       3. ...

  4. SpringMVC视图解析中的 forward: 与 redirect: 前缀

    在 SpringMVC 中,可以指定画面的跳转方式.使用 forward: 前缀实现请求转发跳转,使用 redirect: 前缀实现重定向跳转.有前缀的转发和重定向操作和配置的视图解析器没有关系,视图 ...

  5. Java的数组索引问题

    /* 数组操作的两个常见小问题: ArrayIndexOutOfBoundsException:数组索引越界异常 原因:你访问了不存在的索引. NullPointerException:空指针异常 原 ...

  6. 4.K均值算法--应用

    1. 应用K-means算法进行图片压缩 读取一张图片 观察图片文件大小,占内存大小,图片数据结构,线性化 用kmeans对图片像素颜色进行聚类 获取每个像素的颜色类别,每个类别的颜色 压缩图片生成: ...

  7. php正则匹配到字符串里面的a标签

    $cont = preg_replace('/<a href=\"(.*?)\".*?>(.*?)<\/a>/i','',$cont);

  8. 日志分析工具ELK(一)

    一.ELK介绍 1.1 elasticsearch 1.1.1 elasticsearch介绍 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎 ...

  9. Python3 注释和运算符

    Python3 注释 确保对模块, 函数, 方法和行内注释使用正确的风格 Python中的注释有单行注释和多行注释: Python中单行注释以 # 开头,例如:: # 这是一个注释 print(&qu ...

  10. 【linux三剑客】grep命令

    grep, egrep, fgrep - print lines matching a pattern grep 命令用于查找文件里符合条件的字符串. grep 指令用于查找内容包含指定的范本样式的文 ...