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

    题目链接:https://codeforces.com/contest/1234/problem/C 题目大意:根据规则,判断是否可以从左上走到右下,1,2,3,4,5,6分别对应题干给的图片,所以1 ...

  2. selemiun 下拉菜单、复选框、弹框定位识别

    一.下拉菜单识别 对下拉框的操作,主要是通过Select 类里面的方法来实现的,所以需要new 一个Select 对象(org.openqa.selenium.support.ui.Select)来进 ...

  3. [Laravel框架学习二]:Laravel的CURD和查询构造器的CURD,以及聚合函数

    public function index() { //return Member::getMember();//这是调用模型的方法 return view('lpc',[ 'age'=>18, ...

  4. css中的宽和高

    width width表示宽 height height表示高 max-width.min-width max-width表示最大宽度 min-width表示最小宽度 max-height.min-h ...

  5. PHP中级篇 Apache配置httpd-vhosts虚拟主机总结及注意事项

    经常使用Apache虚拟主机进行开发和测试,但每次需要配置虚拟主机时都习惯性的ctrl+c和ctrl+v,这次由于重装系统,需要配置一个新的PHP开发环境虚拟主机,于是总结一下Apaceh配置http ...

  6. Xtrabackup全量 增量备份详解

    xtrabackup是Percona公司CTO Vadim参与开发的一款基于InnoDB的在线热备工具,具有开源,免费,支持在线热备,备份恢复速度快,占用磁盘空间小等特点,并且支持不同情况下的多种备份 ...

  7. PAT A1023

    简单的大数问题,long long并不能容纳21位数字,这是刚开始没有注意到的 #include<iostream> #include<stdlib.h> #include&l ...

  8. MongoDB学习(四):通过Java使用MongoDB

    环境配置 在Java项目中使用MongoDB,需要在项目中引入mongo.jar这个包.下载地址:下载 请尽量下载较新的版本,本文用的是2.10.1. 连接MongoDB public synchro ...

  9. vue 跳转并传参,实现数据实时更新

    原文链接:点我 比如我现在在页面A跳转到页面B,A中的router-link :to={path:’B’,params:{id:’5’}} 求助:在页面B中的mounted生命周期函数中使用this. ...

  10. Codeforces Round #637 (Div. 2) 题解

    A. Nastya and Rice 网址:https://codeforces.com/contest/1341/problem/A Nastya just made a huge mistake ...