Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)
题目链接:
题目描述:
有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目)。问至少运输p能量的甜点,花费最小是多少?
解题思路:
明显可以看出是多重背包搞两次,但是数据范围太大了,背包要到2*1e6,感觉会TLe。还是呆呆的写了一发,果断超啊!然后滚回去看背包九讲课件了,看到了二进制压缩的时候,感觉可以搞这个题目。试了一下果然AC,原本物品数目是100*100,二进制压缩以后也就是100*log2100个左右,然后进行01背包就OK咯!
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = ;
const int N = ;
int dp[maxn], x, y, c1, c2;
int dcos[N], dval[N], tcos[N], tval[N];
void display ()
{
for (int i=; i<c1+; i++)
dp[i] = INF;
dp[] = ;
for (int i=; i<x; i++)
for (int j=c1+; j>=dval[i]; j--)
dp[j] = min (dp[j], dp[j-dval[i]]+dcos[i]);
c2 = dp[c1];
for (int i=c1; i<c1+; i++)
c2 = min (dp[i], c2);
}
void solve ()
{
memset (dp, , sizeof(dp));
for (int i=; i<y; i++)
for (int j=; j>=tcos[i]; j--)
dp[j] = max (dp[j], dp[j-tcos[i]]+tval[i]);
for (int i=; i<=; i++)
if (dp[i] >= c2)
{
printf ("%d\n", i);
return ;
}
printf ("TAT\n");
}
int main ()
{
int t, n, m;
scanf ("%d", &t);
while (t --)
{
scanf ("%d %d %d", &n, &m, &c1);
int a, b, c;
x = y = ;
for (int i=; i<n; i++)
{
scanf ("%d %d %d", &a, &b, &c);
for (int k=; c; k*=)
{
int num = min (k, c);
dcos[x] = num * b;
dval[x++] = num * a;
c -= num;
}
}
for (int i=; i<m; i++)
{
scanf ("%d %d %d", &a, &b, &c);
for (int k=; c; k*=)
{
int num = min (k, c);
tcos[y] = num * b;
tval[y++] = num * a;
c -= num;
}
}
display ();
solve ();
}
return ;
}
Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)的更多相关文章
- Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)
题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最 ...
- (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )
http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others) Memo ...
- (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)
http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others) ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)
Football Games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- (线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/ ...
- hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online
很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...
- HDU 5437 Alisha’s Party (优先队列)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her f ...
随机推荐
- 杭电1596find the safest road(spfa)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- GPG key
Creating GPG Keys - Fedora Project Wiki https://fedoraproject.org/wiki/Creating_GPG_Keys
- 20170225-ALV tree 显示
1.写程序, 2.话屏幕9000,CALL SCREEN 9000.(双击屏幕进去画个容器就ok,+OK_CODE,+去掉注释) 3.处理好ALV 的PBO 初始化,处理用户事件PAO,user co ...
- vmware Ubuntu忘记登录密码
VMware Workstation 上的Ubuntu 11.10 登录时,用户密码忘记了,以下是我对此问题解决的方法: 1)重新启动Ubtuntu 16 系统,同时长时间按住(或连续点击)esc键进 ...
- 静态代理、动态代理和cglib代理
转:https://www.cnblogs.com/cenyu/p/6289209.html 代理(Proxy)是一种设计模式,提供了对目标对象另外的访问方式;即通过代理对象访问目标对象.这样做的好处 ...
- 对soc-audio体系snd_soc_machine和snd_soc_dai_link简单理解
ASOC (ALSA system on chip) // 主要为嵌入式系统专门开发的sound管理体系结构[luther.gliethttp].Digital Audio ...
- model.js
var Model = { inherited: function () {}, created: function () {}, prototype: { init: function (attrs ...
- js中return的作用
1.终止函数的继续运行. 当遇到if…… else是.若出现return,就会出现终止运行,不会继续做出判断 <html> <head> <title>return ...
- 织梦栏目页分页title加"第N页"
以上就是调用栏目管理的SEO标题代码:{dede:field.seotitle /}的方法,这样充分体现列表页标题显示的效果,有利于搜索引擎的收录. 第二个问题就是这样列表页的标题都成了一个样子的了, ...
- Pyhton:List build-in function
列表是Python中的可迭代对象之一,在讲列表的内建函数之前我们可以自己在IDE上看看都有那些内建函数,我们可以在pycharm中使用代码及其运行结果如下: print(dir(list)) ['__ ...