给你n个工件,然后有A,B,C三个工厂,然后它们加工第i个工件所需要的时间分别为a[i],b[i],c[i],然后现在要你利用三间工厂加工所有的零件,要求是任何时间工厂都不能停工,而且一定要三间同时做完。

理论上是很难突破时间限制的,但是发现sum(a[i]),sum(b[i]),sum(c[i])<=120,那么就可以这么搞 dp[n][x][y][z]表示利用前n个工件可以到达三间工厂的时间分别为x,y,z的转态,每加一个工件则转移多三种状态,因为最多不会有超过120*120*120状态,然后要转移40*120*120*120,有TLE的可能,不过感觉还是挺直接的dp,所以最后会发现其实是可以过的。

#pragma warning(disable:4996)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define ll long long
#define maxn 220
#define eps 1e-7
using namespace std; int dp[130][130][130];
bool vis[130][130][130];
int a[45], b[45], c[45];
int n;
struct Node
{
int a, b, c;
Node(int ai, int bi, int ci) :a(ai), b(bi), c(ci){}
Node(){}
}; int main()
{
while (cin >> n)
{
for (int i = 0; i < n; i++){
scanf("%d%d%d", a + i, b + i, c + i);
}
queue<Node> que[2];
que[0].push(Node(0, 0, 0));
int cur = 0, nxt = 1; Node x;
for (int i = 0; i < n; i++){
memset(vis, 0, sizeof(vis));
while (!que[cur].empty()){
x = que[cur].front(); que[cur].pop();
if (!vis[x.a + a[i]][x.b][x.c]) que[nxt].push(Node(x.a + a[i], x.b, x.c)), vis[x.a + a[i]][x.b][x.c] = true;
if (!vis[x.a][x.b + b[i]][x.c]) que[nxt].push(Node(x.a, x.b + b[i], x.c)), vis[x.a][x.b + b[i]][x.c] = true;
if (!vis[x.a][x.b][x.c + c[i]]) que[nxt].push(Node(x.a, x.b, x.c + c[i])), vis[x.a][x.b][x.c + c[i]] = true;
}
swap(cur, nxt);
}
memset(vis, 0, sizeof(vis));
while (!que[cur].empty()){
Node x = que[cur].front(); que[cur].pop();
vis[x.a][x.b][x.c] = 1;
}
int i;
for (i = 1; i <= 120; i++){
if (vis[i][i][i]){
printf("%d\n", i);
break;
}
}
if (i > 120) puts("NO");
}
return 0;
}

ZOJ3554 A Miser Boss(dp)的更多相关文章

  1. P1352 没有上司的舞会&&树形DP入门

    https://www.luogu.com.cn/problem/P1352 题目描述 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的 ...

  2. HDU 3586 Information Disturbing 树形DP+二分

    Information Disturbing Problem Description   In the battlefield , an effective way to defeat enemies ...

  3. HDU1224 DP

    Free DIY Tour Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. 序列中找子序列的dp

    题目网址: http://codeforces.com/problemset/problem/414/B Description Mashmokh's boss, Bimokh, didn't lik ...

  5. HDU 3853:LOOPS(概率DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description   Akemi Homura is a M ...

  6. hdu 3853LOOPS (概率DP)

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

  7. Survival(ZOJ 2297状压dp)

    题意:有n个怪,已知杀死第i个怪耗费的血和杀死怪恢复的血,和杀死boss耗的血,血量不能超过100,若过程中血小于0,则失败,问 是否能杀死boss(boss最后出现). 分析:就是求杀死n个怪后剩余 ...

  8. 多校7 HDU5816 Hearthstone 状压DP+全排列

    多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...

  9. HDU 3008 Warcraft(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...

随机推荐

  1. xdebug

    必须的有4个(remote_enable 默认没开,所以必要),其它默认值一般可以xdebug.remote_enable=On; //这个是必须xdebug.remote_host=192.168. ...

  2. Android--从相册中选取照片并返回结果

    启动系统相册去选择图片 //从相册中选取的方法 private void selectPhoto(){ Intent intent = new Intent(Intent.ACTION_PICK); ...

  3. poj 1564 Sum It Up

    题目连接 http://poj.org/problem?id=1564 Sum It Up Description Given a specified total t and a list of n ...

  4. Android中使用WebView, WebChromeClient和WebViewClient加载网页

    在android应用中,有时要加载一个网页,如果能配上一个进度条就更好了,而android 中提供了其很好的支持, 其中webView的一系列用法,比如 webView.getSettings().s ...

  5. Linux开机启动程序详解

    Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...

  6. IOS内存管理「1」- 引用计数

  7. DataTemplate 以及Template Selector 学习笔记

    1. 内容控件通过ContentTemplate,列表控件通过itemTemplate 来支持模板绑定.例子如下: 模板定义: xaml: <DataTemplate x:Key="R ...

  8. 【转载】ITU-RBT.656视频标准接口

    ITU-RBT.656视频标准接口 ITU-RBT.656视频标准接口PAL制式(720*576)每场由四部分组成. ● 有效视频数据,分为奇场和偶场,均由288行组成.每行有1440个字节,其中72 ...

  9. .gitignore无效,不能过滤某些文件

    利用.gitignore过滤文件,如编译过程中的中间文件,等等,这些文件不需要被追踪管理. 现象: 在.gitignore添加file1文件,以过滤该文件,但是通过git status查看仍显示fil ...

  10. 典型:Eayui项目aspx页面引用js

    <link href="../Scripts/easyui1.3.5/themes/default/easyui.css" rel="stylesheet" ...