ZOJ 3331 Process the Tasks 双塔Dp
用dp[i][j]表示当前安排好了前i个任务,且机器A和机器B完成当前分配到的所有任务的时间差为j
(这里j可正可负,实现的时候需要加个offset)时,完成这些任务的最早时间。
然后根据j的正负,分别考虑任务i+1的两种分配方法。比如j大于0,A比B后空闲,
这个时候如果再把任务分配给A的话,B空闲知道A开始处理i+1的这段时间,B是不能安排任务的,
也就是说可以看成是非空闲的状态,于是下一个状态的A和B时间差就是i+1任务的长度。 就根据这个思路分几个情况进行处理,可以知道j这维不会超过100(就是上面这个原因),整个程序是100^2的复杂度。
Source Code:
//用dp[i][dt]表示当前安排好了前i个任务,且机器A和机器B完成当前分配到的所有任务的时间差为dt //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ;
const int INF = 0x3f3f3f3f ;
const int offset = ; int dp[][], dt;
int ta[], tb[];
int n; int main () {
std::ios::sync_with_stdio (false);
int i, j, t, k, u, v, numCase = ;
cin >> t;
while (t--) {
cin >> n;
for (i = ; i <= n; ++i) {
cin >> ta[i] >> tb[i];
}
memset (dp, 0x3f, sizeof(dp));
dp[][ + offset] = ; for (i = ; i <= n; ++i) {
for (dt = -; dt <= ; ++dt) {
if (dp[i - ][dt + offset] == INF) continue; if (dt < ) { // B 机器人的工作时间更长
checkmin (dp[i][-tb[i] + offset], dp[i - ][dt + offset] + tb[i]); //放在B上面(继续由机器人B加工
checkmin (dp[i][dt + ta[i] + offset], dp[i - ][dt + offset] + Max(, ta[i] + dt));//放在A上面,继续让机器人A加工
} else { // A 机器人的工作时间更长
checkmin (dp[i][ta[i] + offset], dp[i - ][dt + offset] + ta[i]); //放在A上面,继续让机器人A加工
checkmin (dp[i][dt - tb[i] + offset], dp[i - ][dt + offset] + Max(, tb[i] - dt));//放在B上面,继续由机器人B加工
}
}
} int res = INF;
for(dt = -; dt <= ; ++dt){
checkmin (res, dp[n][dt + offset]);
}
cout << res << endl;
}
return ;
}
ZOJ 3331 Process the Tasks 双塔Dp的更多相关文章
- ZOJ 3331 Process the Tasks(双塔DP)
Process the Tasks Time Limit: 1 Second Memory Limit: 32768 KB There are two machines A and B. T ...
- ZOJ 3331 Process the Tasks
双塔DP. #include<cstdio> #include<cstring> #include<queue> #include<string> #i ...
- ZOJ 2059 The Twin Towers(双塔DP)
The Twin Towers Time Limit: 2 Seconds Memory Limit: 65536 KB Twin towers we see you standing ta ...
- ZOJ2401 Zipper 双塔式 DP(双塔DP)
第二次遇到双塔DP,再写一下. (flag是为了避免memset多次导致的时间浪费) #include<cstdio> #include<cstdlib> #include&l ...
- HDU 3578 Greedy Tino(双塔DP)
Greedy Tino Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- POJ 2609 Ferry Loading(双塔DP)
Ferry Loading Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1807 Accepted: 509 Sp ...
- VIJOS P1037搭建双塔[DP]
描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件,Mr. F决定自己用水晶来搭建一座双塔. Mr. F有N块水晶,每块 ...
- ZOJ 3494 (AC自动机+高精度数位DP)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3494 题目大意:给定一些被禁止的BCD码.问指定范围内不含有 ...
- POJ 1015 Jury Compromise(双塔dp)
Jury Compromise Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33737 Accepted: 9109 ...
随机推荐
- win7 64位 Xsheel
Xsheel5安装后,找不到.dll文件,系统支持不好,不用 Xshell4有时提示 1152:Error 就使用 链接:http://pan.baidu.com/s/1c1s42Y0 密码:098x ...
- 论left-pad的实现
这两天微博上看到左耳朵耗子吐槽了一下node社区的left-pad的代码,原po链接 我也思考了一下 怎么用实现一个left-pad比较合适,上图代码确实比较搓 leftpad功能,就是字符串前面拼指 ...
- IOS 表视图(UITableVIew)的使用方法(7)表视图的编辑功能(拖拉调整排序位置)
除了每个单元行左边的删除和新增图标,UITableView还支持在单元行的右侧显示一个供用户拖拉调整排序位置的控件. 不过如果要显示此控件,UITableView的数据源需要实现以下的方法. -(vo ...
- MVC-03 控制器(1)
Controller(控制器)在ASP.NET MVC中负责控制所有客户端与服务器端的交互,并且负责协调Model与View之间的数据传递,是ASP.NET MVC整体运作的核心角色. 一.关于Con ...
- android 百度最新地图sdk包怎么去除 放大缩小按钮
// 隐藏缩放控件 int childCount = mMapView.getChildCount(); View zoom = null; ; i < childCount; i++) { V ...
- JSTL与EL(转)
基本使用 <c:forEach items="${deptList}" var="dept"> <div ...
- Android 全屏方法
我大概不想赘述什么其他方法,我就说一下我已知在用的方法QAQ requestWindowFeature(Window.FEATURE_NO_TITLE); 设置程序无标题栏 getWindow().s ...
- pyrailgun 0.24 : Python Package Index
pyrailgun 0.24 : Python Package Index pyrailgun 0.24 Download pyrailgun-0.24.zip Fast Crawler For Py ...
- squee_spoon and his Cube VI(贪心,找不含一组字符串的最大长度+kmp)
1818: squee_spoon and his Cube VI Time Limit: 1 Sec Memory Limit: 128 MB Submit: 77 Solved: 22Subm ...
- Python+Django+SAE系列教程9-----Django的视图和URL
第三.四.五章介绍的就是Django中MVC的视图.模板.模型了. 首先来看视图(view),在用Django生成的站点目录中,创建一个view.py文件,这个文件開始是空的.然后我们输入下面内容: ...