Daily Punch-In (1/1)
Portal: Click to open link
Main topic:
Loop through each point and back to the beginning, the route, all output
Topic Ideas:
DFS can.
After nearly one hours of debugging, the error was found at the comment.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN =;
int map[maxn][5],ans[maxn],m;
int cnt = 1;
BOOL VIS[MAXN];
void dfs (int s,int tot)
{
Ans[tot] = s;
for (int i=0;i<3;i++)
{
int next = map[s][i];
if (tot==19&&next==m)//judgement when written s==m, should be the next point is M, because Vis[s]=1, will never be traversed to
{
printf ("%d: ", cnt++);
for (int j=0;j<20;j++)
cout<<ans[j]<< "";
cout<<next<<endl;
}
if (!vis[next]) {
Vis[next] = 1;
DFS (next,tot+1);
Vis[next] = 0;}}
}
int main ()
{for
(int i=1;i<=20;i++)
{
scanf ("%d%d%d",&map[i][0],&map[i][1],& MAP[I][2]);
}
while (~SCANF ("%d", &m) &&m)
{
memset (vis,0,sizeof (Vis));
VIS[M] = 1;
DFS (m,0);
}
return 0;
}