HDU 5445——Food Problem——————【多重背包】
Food Problem
Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 660 Accepted Submission(s): 196
Other than obtaining the desserts, Bell also needs to consider moving them to the game arena. Different trucks may carry different amounts of desserts in size and of course they have different costs. However, you may split a single dessert into several parts and put them on different trucks, then assemble the parts at the game arena. Note that a dessert does not provide any energy if some part of it is missing.
Bell wants to know how much would it cost at least to provide desserts of a total energy of p (most of the desserts are not bought with money, so we assume obtaining the desserts costs no money, only the cost of transportation should be considered). Unfortunately the mathematician is having trouble with her stomach, so this problem is left to you.
For each test case there are three integers n,m,p on the first line (1≤n≤200,1≤m≤200,0≤p≤50000), representing the number of different desserts, the number of different trucks and the least energy required respectively.
The i−th of the n following lines contains three integers ti,ui,vi(1≤ti≤100,1≤ui≤100,1≤vi≤100) indicating that the i−th dessert can provide tienergy, takes up space of size ui and that Bell can prepare at most vi of them.
On each of the next m lines, there are also three integers xj,yj,zj(1≤xj≤100,1≤yj≤100,1≤zj≤100) indicating that the j−th truck can carry at most size of xj , hiring each one costs yj and that Bell can hire at most zj of them.
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
struct Cake{
int energy,siz,amont;
}cakes[220];
struct Truck{
int siz,cost,num;
}trucks[220];
int dp1[55000],dp2[55000];
void ZeroOnePack(int cost,int weight,int V,int *dp,int typ){
if(typ==1)
for(int i=V;i>=cost;i--){
dp[i]=min(dp[i],dp[i-cost]+weight);
}
else
for(int i=V;i>=cost;i--){
dp[i]=max(dp[i],dp[i-cost]+weight);
}
}
void CompletePack(int cost,int weight,int V,int *dp,int typ){
if(typ==1)
for(int i=cost;i<=V;i++){
dp[i]=min(dp[i],dp[i-cost]+weight);
}
else
for(int i=cost;i<=V;i++){
dp[i]=max(dp[i],dp[i-cost]+weight);
}
}
void MultiplePack(int cost,int weight,int amount,int V,int *d,int typ){
if(cost*amount>=V){
CompletePack(cost,weight,V,d,typ);
return ;
}
int k=1;
while(amount>k){
ZeroOnePack(cost*k,weight*k,V,d,typ);
amount-=k;
k*=2;
}
ZeroOnePack(cost*amount,weight*amount,V,d,typ);
}
int main(){
int T,n,m,p;
scanf("%d",&T);
while(T--){
memset(dp1,INF,sizeof(dp1));
memset(dp2,0,sizeof(dp2));
dp1[0]=0;
int vv=0,cc=0;
scanf("%d%d%d",&n,&m,&p);
for(int i=1;i<=n;i++){
scanf("%d%d%d",&cakes[i].energy,&cakes[i].siz,&cakes[i].amont);
vv+=cakes[i].energy*cakes[i].amont;
}
for(int i=1;i<=m;i++){
scanf("%d%d%d",&trucks[i].siz,&trucks[i].cost,&trucks[i].num);
cc+=trucks[i].cost*trucks[i].num;
}
vv=min(50000,vv);
for(int i=1;i<=n;i++){
MultiplePack(cakes[i].energy,cakes[i].siz,cakes[i].amont,vv,dp1,1);
}
cc=min(cc,50000);
for(int i=1;i<=m;i++){
MultiplePack(trucks[i].cost,trucks[i].siz,trucks[i].num,cc,dp2,2);
}
int pos=0;
int tmp=INF;
for(int i=p;i<=vv;i++){
tmp=min(dp1[i],tmp);
}
for(int i=1;i<=cc;i++){
if(dp2[i]>=tmp){
pos=i; break;
}
}
if(pos==0){
printf("TAT\n");
}else{
printf("%d\n",pos);
}
}
return 0;
} /*
555
5 3 34
1 4 1
9 4 2
5 3 3
1 3 3
5 3 2
3 4 5
6 7 5
5 3 8 */
HDU 5445——Food Problem——————【多重背包】的更多相关文章
- hdu 5445 Food Problem 多重背包
Food Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...
- Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)
题目链接: Hdu 5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
- HDU 5445 Food Problem(多重背包+二进制优化)
http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...
- hdu 2844 Coins (多重背包)
题意是给你几个数,再给你这几个数的可以用的个数,然后随机找几个数来累加, 让我算可以累加得到的数的种数! 解题思路:先将背包初始化为-1,再用多重背包计算,最后检索,若bb[i]==i,则说明i这个数 ...
- 题解报告:hdu 1059 Dividing(多重背包、多重部分和问题)
Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...
- hdu 1059 Dividing bitset 多重背包
bitset做法 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a ...
- HDU 2844 Coins(多重背包)
点我看题目 题意 :Whuacmers有n种硬币,分别是面值为A1,A2,.....,An,每一种面值的硬币的数量分别是C1,C2,......,Cn,Whuacmers想买钱包,但是想给人家刚好的钱 ...
随机推荐
- 没办法,SVD就讲的这么好
2)奇异值: 下面谈谈奇异值分解.特征值分解是一个提取矩阵特征很不错的方法,但是它只是对方阵而言的,在现实的世界中,我们看到的大部分矩阵都不是方阵,比如说有N个学生,每个学生有M科成绩,这样形成的一个 ...
- tomcat 自带jdk
http://blog.csdn.net/b452608/article/details/70143466
- Tiny4412学习杂记
1.Android 挂载NFS 使用 busybox mount 来替代mount命令 2.修改Uboot中fastboot最大buff 使用U-boot烧写Android5.0的时候出现 remo ...
- CentOS 7 破解mariadb密码
1.停止mariadb服务: systemctl stop mariadb 2.进入单用户模式: mysqld_safe --skip-grant-tables & 3.切换到另外一个工作组 ...
- PopupWindow --- 弹出底部窗体
第一步 : 布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...
- 将Linux 标准输出,错误输出重定向到文件
1.想要把make输出的全部信息,输出到某个文件中,最常见的办法就是: make xxx > build_output.txt 此时默认情况是没有改变2=stderr的输出方式,还是屏幕,所以, ...
- spring framework 源码
spring framework 各版本源码下载地址 现在spring的源码下载地址真是不好找,这次终于找到了.记录一下,以帮助需要的朋友. https://github.com/spring-pro ...
- SQL查询 若为空显示默认值
COALESCE(a.end_,now()) SELECT COALESCE(NULL,NULL,3,4,5) FROM
- Sharepoint商务智能学习笔记之Powerpivot Service Dmeo(八)
1)在Excel上添加Powerpivot工具栏 第一步,在Excel中启用Powerpivot 工具栏,新建一个空白Excel文件,在左上角点击文件,然后点击选项 2)使用Powerpivot添加数 ...
- Ubuntu tar 解压缩命令详解
tar 解压缩命令详解: -c: 建立压缩档案 -x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只 ...