Task Sequences Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2062 Accepted: 583 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.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.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
競賽圖:圖中的任意兩點間有且僅有一條有向弧連接
求競賽圖中的哈密頓路的算法:
首先,由數學歸納法可證競賽圖在n>=2時必存在哈密頓路;
(1)n=2時顯然;
(2)假設n=k時,結論成立,哈密頓路為V1,V2,...,Vi,...,Vk;
現添加第k+1個結點,若存在弧
若不存在上述的vi,考慮到Vk+1與v1~vk的連通狀況,則只有下面種原哈密頓路的情況:
1.所有的Vi(1,那麼可得哈密頓回路V1,V2,...,Vi,...,Vk,Vk+1;
2.所有的Vi(1,那麼可得哈密頓回路Vk+1,V1,V2,...,Vi,...,Vk;
3.存在一個中間結點m,使得所有的Vi(1<=i<=m)與Vk+1的弧方向為
/* *********************************************** Author :rabbit Created Time :2014/3/25 20:14:43 File Name :12.cpp ************************************************ */ #pragma comment(linker, "/STACK:102400000,102400000") #include#include #include #include #include #include #include #include #include #include #include #include #include #include