POJ 1776 Task Sequences (Hamilton Rd)

Source: Internet
Author: User

Test instructions: Given an adjacency matrix, that is, a forward graph (with a loop), the minimum coverage path is a few, to find out the traversal order;

Idea: The competition chart exists in Hamilton Road, must be able to find a way to traverse all points.

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intmm[1005][1005];Charch[1005];intnxt[50010];intn,m;intMain () {inti,j,k,head,temp;  while(SCANF ("%d", &n)! =EOF)        {GetChar ();  for(i=0; i<n;i++) {gets (ch); Temp=0;  for(j=0; j<n;j++) {Mm[i][j]=ch[temp]-'0'; Temp+=2; } Nxt[i]=-1; }//Read into head=0;  for(i=1; i<n;i++){          if(Mm[i][head]) {//Insert to Headernxt[i]=Head; Head=i; Continue; } J=Head; K=Nxt[j];  while(k!=-1){            if(Mm[j][i]&&mm[i][k]) Break;//Find insertion Positionj=K; K=Nxt[j]; } Nxt[i]=K; NXT[J]=i; Insert} printf ("1\n%d\n", N);  for(i=0; i<n;i++){          if(i==0) {printf ("%d", head+1); }          Elseprintf"%d", head+1); Head=Nxt[head]; }printf ("\ n"); }    return 0;}

POJ 1776 Task Sequences (Hamilton Rd)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.