http://poj.org/problem?id=1776

题意:

有一个机器要完成N个作业,

给你一个N*N的矩阵,

M[i][j]=1,表示完成第i个作业后不用重启机器,继续去完成第j个作业

M[i][j]=0,表示如果做完第i个作业,想要继续去做第j个作业,那么必须重启机器

对于任意两个作业都有M[i][j] = 1或者M[j][i] = 1.

求出完成这N个作业启动机器的最少次数,以及每次启动完成作业的数量和这些作业的顺序

初始时机器处于关闭状态.

将M当做图,就是找最少的路径条数覆盖所有的点

最小路径覆盖?

但不能保证图是二分图,所以不能用匈牙利算法

题目中说对于任意两个作业都有M[i][j] = 1或者M[j][i] = 1

所以这张图是在竞赛图的基础上加了几条边

而竞赛图一定存在一条哈密顿通路

所以一定只需要一次开机完成所有作业

然后就是输出竞赛图上的一条哈密顿通路

详请参见文章http://www.cnblogs.com/TheRoadToTheGold/p/8439160.html

#include<cstdio>
#include<cstring>
#include<iostream>using namespace std;#define N 1001int n;
char s[N<<1];
int e[N][N];int front,nxt[N];int st[N];void Hamilton()
{front=1;memset(nxt,0,sizeof(nxt));for(int i=2;i<=n;++i){if(e[front][i]){nxt[i]=front;front=i;continue;}int j,k;for(j=front;j;k=j,j=nxt[j])if(e[j][i]){nxt[i]=j;nxt[k]=i;break;}if(!j) nxt[k]=i;}
}void print()
{printf("1\n%d\n",n);int now=front;int top=0;while(now){st[++top]=now;now=nxt[now];}for(int i=top;i>1;--i) printf("%d ",st[i]);printf("%d\n",st[1]);
}int main()
{while(scanf("%d",&n)!=EOF){memset(e,false,sizeof(e));for(int i=1;i<=n;++i) {getchar();scanf("%[^\n]",s);int t=0;for(int j=0;t<n;j+=2) e[i][++t]=s[j]-'0';}Hamilton();print();}
}     

Task Sequences
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2637   Accepted: 763   Special Judge

Description

Tom has received a lot of tasks from his boss, which are boring to deal with by hand. Fortunately,Tom got a special machine - Advanced Computing Machine (ACM) to help him. 
ACM works in a really special way. The machine can finish one task in a short time, after it's finishing one task, it should smoothly move to the next one, otherwise the machine will stop automatically. You must start it up again to make it continue working. Of course, the machine cannot move arbitrarily from one task to another. So each time before it starts up, one task sequence should be well scheduled. Specially, a single task also can be regarded as a sequence. In the sequence, the machine should be able to smoothly move from one task to its successor (if exists). After started up, the machine always works according to the task sequence, and stops automatically when it finishes the last one. If not all the tasks have been finished, the machine has to start up again and works according to a new sequence. Of course, the finished tasks can't be scheduled again. 
For some unknown reasons, it was guaranteed that for any two tasks i and j, the machine can smoothly move from i to j or from j to i or both. Because the startup process is quite slow, Tom would like to schedule the task sequences properly, so that all the tasks can be completed with minimal number of startup times. It is your task to help him achieve this goal.

Input

Input contains several testcases. For each testcase, the first line contains only one integer n, (0 < n <= 1,000), representing the number of tasks Tom has received. Then n lines follow. Each line contains n integers, 0 or 1, separated by white spaces. If the jth integer in the ith line is 1, then the machine can smoothly move from task i to task j, otherwise the machine can not smoothly move from task i to task j. The tasks are numbered from 1 to n. 
Input is terminated by end of file.

Output

For each testcase, the first line of output is only one integer k, the minimal number of startup times needed. And 2k lines follow, to describe the k task sequences. For each task sequence, the first line should contain one integer m, representing the number of tasks in the sequence. And the second line should contain m integers, representing the order of the m tasks in the sequence. Two consecutive integers in the same line should be separated by just one white space. Extra spaces are not allowed. There may be several solutions, any appropriate one is accepted.

Sample Input

3
0 1 1
1 0 1
0 0 0

Sample Output

1
3
2 1 3

Source

Asia Guangzhou 2003

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8439853.html

poj 1776 Task Sequences相关推荐

  1. ADK+MDT实现域控服务器全自动静默下发系统(五):MDT的部署--Task Sequences的配置

    日常中最常用的安装系统方式为U盘手动安装,或是借助第三方一键装机工具进行安装.但是对于身处在一家公司中的运维人员,经常需要安装系统,甚至有时需要在有限的时间内安装多台系统.这种情况如果还是使用上述两种 ...

  2. poj 2034 Anti-prime Sequences(dfs)

    http://poj.org/problem?id=2034 大致题意:给出区间[n,m],对这个区间的数进行排列使得相邻的2个.3个......d个数之和都不是素数.输出字典序最小的. 思路:裸的d ...

  3. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  4. NOIP 好题推荐(DP+搜索+图论)POJ ZOJ

    NOIP好题推荐(DP+搜索+图论)POJ ZOJ 1370 Gossiping (数论->模线性方程有无解的判断)+(图论->DFS)  1090 Chain ->格雷码和二进制码 ...

  5. POJ 动态规划题目列表

    1.这份列表当然不是我原创的,从文库里下载了一份,放到这里便于自己浏览和查找题目. ※最近更新:Poj斜率优化题目 1180,2018,3709 列表一:经典题目题号: 容易:  1018, 1050 ...

  6. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  7. POJ的题目分类(两个版本)

    版本一: 简单题 1000A+B Problem 1001Exponentiation 1003 Hangover 1004 Financial Management 1005 I Think I N ...

  8. poj动态规划经典题目

    列表一:经典题目题号: 容易: 1018, 1050, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1191,1208, 1276, 1322, 1 ...

  9. 【转】别人整理的DP大全

    为什么80%的码农都做不了架构师?>>>    动态规划 动态规划 容易: 1018 , 1050 , 1083 , 1088 , 1125 , 1143 , 1157 , 1163 ...

最新文章

  1. 常用memcached命令详解
  2. 一个KindEditor的插件[myFocus]
  3. jClarity发布Censum 3.0
  4. 如何让本机时间与局域网的一台电脑的日期同步?
  5. 带有Spring的REST的ETag
  6. IE或Chrome浏览器玩Xbox游戏能实现吗
  7. 操作系统之内存管理:6、页面分配策略、抖动、工作集
  8. CentOS8.1 搭建jenkins
  9. 安卓学习笔记20:Fragment入门
  10. js之table操作
  11. 杭电计算机组成原理实践课 实验2 一位全加器构成的四位全加器
  12. qcom usb驱动下载_艾肯Mobile Q驱动下载
  13. 理解 Mach-O 并提高程序启动速度
  14. 微信点餐系统的开发与实现
  15. 贝壳CVR转化率预估模型实践
  16. 计算机科学基础刘小丽,刘小丽
  17. ctrl键频繁失灵,但不是键盘本身的问题,换个键盘同样失灵
  18. 万能  随机森林回归 补缺函数
  19. canvas效果案例:安卓机器人
  20. 《科技创业启示录》一第3章 拉尔斯·欣里希斯

热门文章

  1. [Java][Servlet] Failed to destroy end point associated with ProtocolHandler [http-nio-8080]
  2. LeetCode(118)——杨辉三角(JavaScript)
  3. Unity如何设置两个玩家
  4. 电脑黑屏的原因有哪些
  5. 新买的衣服一定要洗吗?不洗就穿对身体不好吗?
  6. 失眠患者应该边工作边调理,还是辞职回家调理?
  7. 我想问一下男生,一个女生那么真诚热情又卑微的喜欢你,你们是怎么做到视而不见的呢?
  8. 家用车多少马力才够用?
  9. 闲 鱼,进阶技巧,如何提高你的曝光量?
  10. 又到年关,年终奖你能拿多少?