1040: Schedule

Time Limit: 500 MS  Memory Limit: 64 MB
Submit: 12  Solved: 2
[Submit][Status][Web Board]

Description

  Resently, loneknight is doing research on job shop schedule problem(JSP for short). Let us take a look at JSP, there are n jobs and m machines, and every job must be processed in every machines, with a process time t[i,j] for job i being processed in machines j. One restrain is that the order for each job processed in machines is fixed, which means that for every job i, there is a process oder (a[i,1], a[i,2], ..., a[i,m]), job i must processed in machine a[i,1] first then a[i,2], ..., a[i,m]. Another restrain is every machine can process amost one job at any time, and every job can be process in amost one machine at any time. The problem is to find a schedule fit this restrains, that make the end time for all jobs, namely the makespan is minimum. Because of the fact that JSP is a NP-Complete problem, loneknight try using simulated anealing and gene algorithm to construct a heuristics algorithm for it. In developing such algorithm for JSP, he confront with a problem that if a schedule is already given, what is the makespan of this schedule, now this your task to solve this problem.

Input

  There are mutiple test cases in the input. The beginning of each case is n, the number of jobs, m, the number of machines. (0 < n,m <= 300) Each follow three components. First is a nxm matrix, the value in the ith row and jth column is t[i,j]. (0 <= t[i,j] < 100) Second is a nxm matrix, the jobs process order, the value in the ith row and jth column is a[i,j]. Third is a mxn matrix the machines process order, the value in the ith row and jth column is b[i,j], (b[i,1], b[i,2], ..., b[i,n]) is the jobs process order in machine i, which means machine i process b[i,1] first, then b[i,2], ..., b[i,n]. (jobs and machines are indexed from 1) The input end with EOF

Output

  For each test case, you should output a single integer, which is the makespan for that schedule in a single line.

Sample Input

3 3
83 86 77 
15 93 35 
86 92 49

3 1 2 
3 1 2 
1 3 2

1 2 3 
1 3 2 
1 2 3

Sample Output

495

HINT

 

Source

[Submit][Status][Web Board]

题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1040

题目大意:

  有N个任务,M台机器,每个任务都必须在M台机器上运行一次才行。

  任务i在机器j上的运行时间为T[i][j]

  任务i必须满足先在机器A[i][1]上运行完才能在A[i][2]上,A[i][3]...A[i][m]上(按A[i]的顺序运行)

  机器j必须满足先运行任务B[j][1]才能再运行B[j][2],...,B[j][n](按B[j]顺序运行)

  问所有任务完成的时间。

题目思路:

  【拓扑排序】

  首先可以知道,如果一个任务在某一个机器上做需要之前的步骤都已经完成,每一个机器做当前任务也需要之前的任务均完成

  所以按照这个建图,按照第i个任务第j个机器设为节点A[i][j]。由于每个任务都有机器的先后顺序,每个机器也有任务的先后顺序

  所以A[i][j]往它的下一个任务,下一个机器连一条边。

  (一开始用SPFA写T了。。)  

  之后拓扑排序,每次更新最长路径的值。最后的答案即为解。

  d[xx][yy]=max{ d[x][y]+t[xx][yy] }

  

 /****************************************************

     Author : Coolxxx
Copyright 2017 by Coolxxx. All rights reserved.
BLOG : http://blog.csdn.net/u010568270 ****************************************************/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
const double EPS=1e-;
const int J=;
const int MOD=;
const int MAX=0x7f7f7f7f;
const double PI=3.14159265358979323;
const int N=;
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int t[N][N],a[N][N],b[N][N],d[N][N],in[N][N];
int nex[N][N][][];
void tuopu()
{
int i,j,x,y,xx,yy;
mem(d,);
queue<int>qx,qy;
for(i=;i<=n;i++)
{
if(!in[i][a[i][]])
{
d[i][a[i][]]=t[i][a[i][]];
qx.push(i);
qy.push(a[i][]);
}
}
while(!qx.empty())
{
x=qx.front();qx.pop();
y=qy.front();qy.pop();
for(i=;i<;i++)
{
xx=nex[x][y][i][];
yy=nex[x][y][i][];
if(!x || !y)continue;
d[xx][yy]=max(d[xx][yy],d[x][y]+t[xx][yy]);
if(!--in[xx][yy])
{
qx.push(xx);
qy.push(yy);
}
}
ans=max(ans,d[x][y]);
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k,l;
int x,y,z;
// for(scanf("%d",&cass);cass;cass--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
ans=;
mem(nex,);mem(in,);
scanf("%d",&m);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&t[i][j]);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&a[i][j]);
for(i=;i<=m;i++)
for(j=;j<=n;j++)
scanf("%d",&b[i][j]);
for(i=;i<=n;i++)
{
for(j=;j<m;j++)
{
nex[i][a[i][j]][][]=i,
nex[i][a[i][j]][][]=a[i][j+];
in[i][a[i][j+]]++;
}
}
for(i=;i<=m;i++)
{
for(j=;j<n;j++)
{
nex[b[i][j]][i][][]=b[i][j+],
nex[b[i][j]][i][][]=i;
in[b[i][j+]][i]++;
}
}
tuopu();
printf("%d\n",ans);
}
return ;
}
/*
// //
*/

XMU 1040 Schedule 【拓扑排序】的更多相关文章

  1. LeetCode 210. Course Schedule II(拓扑排序-求有向图中是否存在环)

    和LeetCode 207. Course Schedule(拓扑排序-求有向图中是否存在环)类似. 注意到.在for (auto p: prerequistites)中特判了输入中可能出现的平行边或 ...

  2. LeetCode 207. Course Schedule(拓扑排序)

    题目 There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have p ...

  3. 2-sat 输出任意一组可行解&拓扑排序+缩点 poj3683

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8170   Accept ...

  4. Poj 3683-Priest John's Busiest Day 2-sat,拓扑排序

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8872   Accept ...

  5. LeetCode编程训练 - 拓扑排序(Topological Sort)

    拓扑排序基础 拓扑排序用于解决有向无环图(DAG,Directed Acyclic Graph)按依赖关系排线性序列问题,直白地说解决这样的问题:有一组数据,其中一些数据依赖其他,问能否按依赖关系排序 ...

  6. 拓扑排序 Topological Sort

    2018-05-02 16:26:07 在计算机科学领域,有向图的拓扑排序或拓扑排序是其顶点的线性排序,使得对于从顶点u到顶点v的每个有向边uv,u在排序中都在v前.例如,图形的顶点可以表示要执行的任 ...

  7. hdu 4857(好题,反向拓扑排序)

    逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submissi ...

  8. Gym 100792 King's Rout 拓扑排序

    K. King's Rout time limit per test 4.0 s memory limit per test 512 MB input standard input output st ...

  9. poj 3683(2-sat+拓扑排序)

    Priest John's Busiest Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11127   Accep ...

随机推荐

  1. Cloudera’s Distribution Including Apache Hadoop(CDH)安装过程

    文档地址:https://www.cloudera.com/documentation.html                 https://www.cloudera.com/documentat ...

  2. qrcode.js扫码邀请

    //js引用部分<script src="../qrcode.js" type="text/javascript"></script> ...

  3. 关于Python构建微服务的思考(一)

    一:什么是微服务? 微服务是一种架构风格,一个大型复杂软件应用由一个或多个微服务组成. 系统中的各个微服务可被独立部署,各个微服务之间是松耦合的. 每个微服务仅关注于完成一件任务并很好地完成该任务. ...

  4. Matlab学习笔记(一)

    一.MATLAB概述 (一)运行环境 命令行窗口(Command Window) 表 1-1 数据显示格式设置(e_one_1.m) 格式 实例 说明 format short 3.1416 小数点后 ...

  5. LeetCode 123. Best Time to Buy and Sell Stock III (stock problem)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  6. 【Codeforces 1041D】Glider

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 二分. 枚举每一个上升区的起始位置作为起点(这样做肯定是最优的),然后如果没有掉在地上的话就尽量往右二分(只有上升区之间的间隙会让他往下掉) ...

  7. Linux下汇编语言学习笔记33 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  8. Codeforces 628D Magic Numbers

    题意: 求在[a,b](a,b不含前导0)中的d−magic数中有多少个是m的倍数. 分析: 计数dp Let's call a number d-magic if digit d appears i ...

  9. 如何使用TFTP客户端工具修复路由器固件

    如何使用TFTP客户端工具修复路由器固件 编号:12083       来自:NetGear       更新日期:2013-10-14       访问数量:24650 NETGEAR无线路由器中, ...

  10. java MAT 分析

    java MAT 分析 http://blog.csdn.net/qeqeqe236/article/details/43577857 https://www.cnblogs.com/AloneSwo ...