UVA 690 Pipeline Scheduling
https://vjudge.net/problem/UVA-690
题目
你有一台包含5个工作单元的计算机,还有10个完全相同的程序需要执行。每个程序需要$n(n<20)$个时间片来执行,可以用一个5行n列的保留表(reservation table)来表示,其中每行代表一个工作单元(unit0~unit4),每列代表一个时间片,行i列j的字符为X表示“在程序执行的第j个时间片中需要工作单元i”。例如,如图所示就是一张保留表,其中程序在执行的第0,1,2,……个时间片中分别需要unit0,unit1,unit2……
同一个工作单元不能同时执行多个程序,因此若两个程序分别从时间片0和1开始执行,则在时间片5时会发生冲突(两个程序都想使用unit0),如图所示。
输入一个5行n(n<20)列的保留表,输出所有10个程序执行完毕所需的最少时间,例如,对于图中的保留表,执行完10个程序最少需要34个时间片。
| clock | 0 | 1 | 2 | 3 | 4 | 5 | 6 | clock | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
| unit0 | X | . | . | . | X | X | . | unit0 | 0 | 1 | . | . | 0 | C | 1 | . | |
| unit1 | . | X | . | . | . | . | . | unit1 | . | 0 | 1 | . | . | . | . | . | |
| unit2 | . | . | X | . | . | . | . | unit2 | . | . | 0 | 1 | . | . | . | . | |
| unit3 | . | . | . | X | . | . | . | unit3 | . | . | . | 0 | 1 | . | . | . | |
| unit4 | . | . | . | . | . | . | X | unit4 | . | . | . | . | . | . | 0 | 1 |
题解
我是真的服了这题了……还有昨天每次评测都要排半小时的队……
1.直接模拟,加上剪枝:如果剩余的程序全部使用最短移动仍然超过了当前最短的时间,那么就剪枝。提前计算移动的步数。但是这个方法容易TLE……
2.使用二进制压缩状态,加上剪枝

每次移动只需要判断原来的状态向后移与程序的保留表是否有冲突,如果没有,将这两个取并作为新的状态。
AC代码
#include<bits/stdc++.h>
using namespace std;
#define REP(r,x,y) for(register int r=(x); r<(y); r++)
#define REPE(r,x,y) for(register int r=(x); r<=(y); r++)
#define MAXN 17
#ifdef sahdsg
#define DBG(...) printf(__VA_ARGS__)
#else
#define DBG(...)
#endif
int n;
int maxd; int ans;
int tmp[5];
int can[450],cani=0;
void dfs(int d, int x, int pos, const int* lp) {
if(pos+(9-d)*can[0]+n>=ans) { return;}
REP(i,0,5) {
if(tmp[i] & (lp[i]>>x)) return;
}
int np[5]; memcpy(np,lp,sizeof np); REP(i,0,5) {
np[i] = tmp[i] | (np[i]>>x);
} if(d==9) {
// assert(false);
ans = min(ans,pos+n);
} else {
REP(i,0,cani) {
dfs(d+1,can[i], pos+can[i],np);
}
} }
int main() {
#ifdef sahdsg
freopen("in.txt", "r", stdin);
#endif
while(~scanf("%d", &n) && n) {
// memset(vis,0,sizeof vis);
// memset(pic,0,sizeof pic);
maxd=-1;
cani=0;
memset(tmp,0,sizeof tmp);
REP(i,0,5) REP(j,0,n) {
char ch=getchar();
while(ch<' ') ch=getchar();
if(ch=='X') {
// pic[i][j]=1;
maxd=max(maxd,j);
tmp[i]|=1<<j;
}
}
REPE(d,1,maxd+1) {
REP(i,0,5){
if(tmp[i] & (tmp[i]>>d)) goto nxt;
}
can[cani++]=d;
nxt:;
}
if(maxd==-1) assert(false);
else {
ans=9*(maxd+1)+n;
REP(i,0,cani) {
dfs(1,can[i], can[i],tmp);
}
}
printf("%d\n", ans);
}
return 0;
}
UVA 690 Pipeline Scheduling的更多相关文章
- 【暑假】[深入动态规划]UVa 1380 A Scheduling Problem
UVa 1380 A Scheduling Problem 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=41557 ...
- UVA 1380 A Scheduling Problem
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 690 PipelineScheduling 位运算+dfs+剪枝
一开始最容易想到间隔最多为n,但是结点还是太多了,需要优化. 预处理:预判一下并保存下一个可以放的位置距离之前的距离.这样可以减少很多判断. 最优化剪枝:如果当前长度+剩下没放的程序*最短间隔如果大于 ...
- 【习题 7-5 UVA-690】Pipeline Scheduling
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 一定在这里写完思路再敲代码!!! 处理出5个工作单元在哪些时刻会被用到. ->设为initstatu 因为每次都会面临之前已经 ...
- UVA 607 二十二 Scheduling Lectures
Scheduling Lectures Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- 【UVA 1380】 A Scheduling Problem (树形DP)
A Scheduling Problem Description There is a set of jobs, say x1, x2,..., xn <tex2html_verbatim_ ...
- 递推DP UVA 607 Scheduling Lectures
题目传送门 题意:教授给学生上课,有n个主题,每个主题有ti时间,上课有两个限制:1. 每个主题只能在一节课内讲完,不能分开在多节课:2. 必须按主题顺序讲,不能打乱.一节课L时间,如果提前下课了,按 ...
- A trip through the Graphics Pipeline 2011_13 Compute Shaders, UAV, atomic, structured buffer
Welcome back to what’s going to be the last “official” part of this series – I’ll do more GPU-relate ...
- A trip through the Graphics Pipeline 2011_01
It’s been awhile since I posted something here, and I figured I might use this spot to explain some ...
随机推荐
- Java入门篇(五)——字符串/String类
前面在举例时有出现过String的例子,当时肯定有一部分朋友不知道这个是做什么用的.其实String类是Java中一个比较特殊的类,字符串即String类,它不是Java的基本数据类型之一,但可以像基 ...
- 解决IsEditable="True"的ComboBox在DataGrid中点击一次不能选中行的问题
原文:解决IsEditable="True"的ComboBox在DataGrid中点击一次不能选中行的问题 此方法很笨拙,并不推荐使用!!! 此方法很笨拙,并不推荐使用!!! 此方 ...
- @Vue/Cli 3 Invalid Host header 检测关闭
Invalid Host header 在本地开发等一般情况下,无论是 local,还是 ip,或者是 0.0.0.0,在 cli 中都默认为合法的,但是有些场景可能会被不支持,比如远程开发,或者是云 ...
- 前端自动化 shell 脚本命令 与 shell-node 脚本命令 简单使用 之 es6 转译
(背景: 先用 babel 转译 es6 再 用 browserify 打包 模块化文件,来解决浏览器不支持模块化 )(Browserify是一个让node模块可以用在浏览器中的神奇工具) 今天折腾了 ...
- 广州商学院16级软工一班&二班-第二次作业成绩
作业地址 https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 https://edu.cnblogs.com/campus/gzc ...
- WinRAR从入门到高级的操作技巧集合
一.基础技巧 1.批量建立文件夹 如果在工作中,经常要建立很多相同文件夹结构(如在备份数据时).那可以把这个繁琐的工作让WinRAR完成:先在“资源管理器”中把多个文件夹结构建好(包括其下的子文件夹) ...
- NEST.net Client
NEST.net Client For Elasticsearch简单应用 由于最近的一个项目中的搜索部分要用到 Elasticsearch 来实现搜索功能,苦于英文差及该方面的系统性资料不好找,在实 ...
- Excel之批量改变特定字体颜色(转载)
改变单元格内部分特定字符的颜色,如果批量操作,需要用宏处理, 如下例,将范围内 所有字母A 变成红色 操作步骤:右键点击工作表标签,查看代码,如下代码复制进去Private Sub CommandBu ...
- PV、TPS、QPS计算公式(转)
英文解释: PV=page viewTPS=transactions per secondQPS=queries per secondRPS=requests per second RPS=并发数/平 ...
- mybatis入门配置和调试
欢迎转载http://www.cnblogs.com/jianshuai520/p/8669177.html大家一起努力,如果看的时候有图片半边遮挡起来的话,右键查看图片,就可以观看完整的图片,具体怎 ...