题意:给你n种食物,m种车,每种食物有三种属性能量值t,体积u,数量v。每种车有三个属性值容量x,价格y,数量z。问题是在能够达到至少p能量的要求下,最小花费为多少,若大于50000则输出TAT。

分析:我们可以首先用0\1背包把在达到p能量的情况下的最小体积先搞出来,因为一个物品最大能量值<=100,故只用背到p + 100,就好了。然后再考虑在50000块以内能够得到的最大体积为多少。然后在两个数组中扫一遍就好了。

code:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2005;
const int INF = 0x3f3f3f3f;
const int M = 55555;
int t[N],u[N],v[N];
int x[N],y[N],z[N];
int dp1[2][M],dp2[2][M];
int V[N],C[N],tcnt;
void init(){memset(dp1,0x3f,sizeof(dp1));memset(dp2,0,sizeof(dp2));dp1[0][0] = 0;
}
void calc(int a[],int b[],int c[],int id){int num = 1;int vv = c[id];while(vv){if(num <= vv){V[tcnt] = a[id] * num;C[tcnt] = b[id] * num;vv -= num;}else{V[tcnt] = a[id] * vv;C[tcnt] = b[id] * vv;vv = 0;}num *= 2;tcnt ++;}
}
void solve(){int n,m,p;init();scanf("%d%d%d",&n,&m,&p);p += 155;for(int i = 0 ; i < n ; i ++)scanf("%d%d%d",&t[i],&u[i],&v[i]);for(int i = 0 ; i < m ; i ++)scanf("%d%d%d",&x[i],&y[i],&z[i]);tcnt = 0;for(int i = 0 ; i < n ; i ++) calc(u,t,v,i);int cur = 0;for(int i = 0 ; i < tcnt ; i ++){cur ^= 1;for(int j = p ; j >= C[i] ; j --)dp1[cur][j] = min(dp1[cur ^ 1][j],dp1[cur ^ 1][j - C[i]] + V[i]);for(int j = 0 ; j < C[i] ; j ++) dp1[cur][j] = dp1[cur ^ 1][j];}int Minv = INF;for(int i = p - 155 ; i <= p ; i ++) Minv = min(Minv,dp1[cur][i]);cur = tcnt = 0;for(int i = 0 ; i < m ; i ++) calc(x,y,z,i);for(int i = 0 ; i < tcnt ; i ++){cur ^= 1;for(int j = 50000 ; j >= C[i] ; j --){dp2[cur][j] = max(dp2[cur ^ 1][j],dp2[cur ^ 1][j - C[i]] + V[i]);}for(int j = 0  ; j < C[i] ; j ++) dp2[cur][j] = dp2[cur ^ 1][j];}int res = -1;for(int i = 0 ; i <= 50000 ; i ++)if(dp2[cur][i] >= Minv){res = i;break;}if(res == -1) printf("TAT\n");else printf("%d\n",res);
}
int main(){int _;scanf("%d",&_);while(_--) solve();return 0;
}

【HDU 5445】Food Problem(DP)相关推荐

  1. 【HDU - 2089 】不要62 (dp)

    题干: 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).  杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客 ...

  2. *【HDU - 5707】Combine String(dp)

    题干: Given three strings aa, bb and cc, your mission is to check whether cc is the combine string of  ...

  3. 【CF 149D】Coloring Brackets(dp)

    [CF 149D]Coloring Brackets(dp) D. Coloring Brackets time limit per test 2 seconds memory limit per t ...

  4. 【HDU 3400】Line belt(三分法)

    题目链接 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3400 题意 有两条传送带AB和CD,移动速度分别为p,q. 除了传送带的其他区域移动速度为r ...

  5. 【CodeForces - 706C】Hard problem(dp,字典序)

    题干: Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, ...

  6. 【HDU - 5009】Paint Pearls(dp,链表优化dp)

    题干: Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color ...

  7. 【HDU - 4055】Number String(dp,思维)

    题干: The signature of a permutation is a string that is computed as follows: for each pair of consecu ...

  8. 【HDU - 2546】饭卡 (dp,0-1背包,贪心思想)

    电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家 ...

  9. 【CodeForces - 1096D】Easy Problem(dp,思维)

    题目大意: 现在有一个由小写字母组成的字符串,去掉这个字符串的第i个位置的字符会有ai的代价.你的任务是去掉这个字符串中的一些字符使得该字符串中不包含子序列hard,且去掉字符的代价之和尽可能小. 输 ...

最新文章

  1. 取值范围_从int取值范围谈起
  2. C++网络包截取开发
  3. python3 module 'pexpect' has no attribute 'spawn' 解决方法
  4. 【MM】SAP委外加工服务验收产生的会计凭证
  5. Django学习~1
  6. abcde依次进入一个队列_详解队列队形及口令(新教师必看)
  7. Comet OJ(Contest #14)-飞翔的小鸟【tarjan】
  8. Oracle 游标范例
  9. python+selenium 爬携程机票价格
  10. linux解析json指针,Linux下JSON通信协议的使用和解析
  11. WordPress 5.0禁用古滕堡编辑器的方法
  12. 语音识别相关书籍抖音十大先看哪一本最好
  13. BM3D图像去噪算法原理及代码详解
  14. Java中的锁有哪些?
  15. Shiro框架 Subject、SecurityManager、线程之间的关系
  16. 山西流传于百姓餐桌的宫府名菜——山西过油肉
  17. C# mschart 控件 框选 删除部分数据 及游标CursorX CursorY 使用
  18. Linux进程守护者: 进程监视及自动重启崩溃的进程
  19. 【区块链论文整理】ICDE 篇
  20. 山海演武传·黄道·第一卷 雏龙惊蛰 第五章 蛮族少女与白泽

热门文章

  1. 01. 微信小程序音乐播放器
  2. STP/RSTP/MSTP的概念及特点
  3. STM32 HAL I2C(IIC)通信的序列传输(restart condition)
  4. Android开发— Android API Levels
  5. 电视服务器媒体流中断是什么意思,视频流媒体服务器稳定吗?出现播放中断问题怎么办?...
  6. 把若干个亚群合并到一起得到subsetdata merge到一起
  7. python \x0d\x0a \x0a
  8. 30岁的程序员你不懂
  9. 电脑上怎么批量将视频变小
  10. JavaWeb和JavaScript的学习