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 1001 int n;
char s[N<<];
int e[N][N]; int front,nxt[N]; int st[N]; void Hamilton()
{
front=;
memset(nxt,,sizeof(nxt));
for(int i=;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=;
while(now)
{
st[++top]=now;
now=nxt[now];
}
for(int i=top;i>;--i) printf("%d ",st[i]);
printf("%d\n",st[]);
} int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(e,false,sizeof(e));
for(int i=;i<=n;++i)
{
getchar();
scanf("%[^\n]",s);
int t=;
for(int j=;t<n;j+=) e[i][++t]=s[j]-'';
}
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

poj 1776 Task Sequences的更多相关文章

  1. POJ 1776 Task Sequences(竞赛图构造哈密顿通路)

    链接:http://poj.org/problem?id=1776 本文链接:http://www.cnblogs.com/Ash-ly/p/5458635.html 题意: 有一个机器要完成一个作业 ...

  2. POJ 1239 Increasing Sequences 动态规划

    题目链接: http://poj.org/problem?id=1239 Increasing Sequences Time Limit: 1000MSMemory Limit: 10000K 问题描 ...

  3. POJ 3553 Task schedule

    原题链接:http://poj.org/problem?id=3553 这道题主要就是贪心思想吧,对于每个job,根据其截止时间 dj 从小到大排序,我们必须要尽快把dj最小的job完成掉,这样才能使 ...

  4. POJ 1239 Increasing Sequences(经典的两次dp)

    http://poj.org/problem?id=1239 题意:给出一串序列,现在要添加逗号作为分隔符,使得序列是递增序列,然后让最后一个数尽量小,第一个数尽量大. 思路:先从头到尾进行一次dp, ...

  5. POJ 3553 Task schedule【拓扑排序 + 优先队列 / 贪心】

    Task schedule Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 515 Accepted: 309 Special J ...

  6. poj 2034 Anti-prime Sequences(dfs)

    //相邻的 2.3......d 之和都要不为素数 # include <algorithm> # include <stdio.h> using namespace std; ...

  7. UVALIVE 2954 Task Sequences

    竞赛图:图中的任意两点间有且仅有一条有向弧连接 求竞赛图中的哈密顿路的算法: 首先,由数学归纳法可证竞赛图在n>=2时必存在哈密顿路: (1)n=2时显然: (2)假设n=k时,结论成立,哈密顿 ...

  8. POJ 1239 Increasing Sequences [DP]

    题意:略. 思路:进行两次dp. 第一次dp从前向后,用dp[x]表示从第x位向前dp[x]位可构成一个数字,且与前面的数组符合题意要求.最后求的dp[n]即为最后一个数字的长度. 而题目还有要求,所 ...

  9. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

随机推荐

  1. SpringBoot日记——信息修改PUT篇

    我们常用的功能,除了post和get,还有put和delete,这篇文章就介绍一下这个put的基本用法. 页面跳转和回显 1. 首先,我们之前的页面已经将添加和修改的按钮都做好了,那么如何实现这些按钮 ...

  2. Asp.Net_后台代码访问前台html标签

    //单击按钮后批量改变li元素的内联文本值及样式 ; i <= ; i++) { HtmlGenericControl li = this.FindControl("li" ...

  3. RabbitMQ使用注意

    1.通常发布者发布结束后会释放Channel,但是消费者由于是异步监听,消费者的Channel不可以释放,否则就断开连接无法监听. 2.当使用默认配置时,ConnectionFactory不指定Por ...

  4. 按键精灵对APP自动化测试(下)

    上一篇介绍了安卓app上使用按键精灵的实践,这里再来说说苹果上的app. 由于iOS相关工具对操作系统的限制,目前在iOS10.0.2系统上应用成功. 二.       苹果手机按键精灵APP录制 适 ...

  5. 代理神器allproxy

    背景 allproxy意为all as proxy,即是说所有设备均可以成为一个网络代理,唯一的要求就是有网络访问权限. 一般的代理软件要求宿主机必须有公网地址,然后才能把网络代理出去,但在实际情况下 ...

  6. Pi Zero三代版本演化比较

    本文介绍Pi Zero的版本演进. 5美元的Pi Zero一上市即造成轰动! 2015年11月树莓派基金会发表了只有5美元的树莓派计算机:PiZero,且只要购买纸本的第40期MagPi杂志就可以附送 ...

  7. 右键添加使用Sublime打开

    网上教程大多是教你怎么改注册表,有点麻烦. 我根据教程改完之后导出来供大家使用,更方便快捷. Windows Registry Editor Version 5.00 [HKEY_CLASSES_RO ...

  8. linux内核分析第二周

    网易云课堂linux内核分析第二周 20135103                王海宁 <Linux内核分析>MOOC课程http://mooc.study.163.com/cours ...

  9. 实验作业:使gdb跟踪分析一个系统调用内核函数

    实验作业:使gdb跟踪分析一个系统调用内核函数(我使用的是getuid) 20135313吴子怡.北京电子科技学院 [第一部分] 根据视频演示的步骤,先做第一部分,步骤如下 ①更新menu代码到最新版 ...

  10. linux 远程连接报错 10038或者10061 或者10060

    1.检查linux的mysql是否开启 2.检查mysql的user表的host是否是% 3.检查my.cnf文件是否绑定本地 4.防火墙3306端口是否开启 假如以上都没问题,那最大的原因就是我折腾 ...