// 0812016.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "conio.h" #define MAX 100 struct graph { int n; int L[MAX][MAX]; }; typedef struct graph GRAPH; GRAPH g; int chuaxet[MAX]; int hamilton[MAX+1]; int soct, sodd; int DocFile(char *s); void CTHamilton(int lan); void DDHamilton(int lan); void InHamilton(int n); void main() { if(!DocFile("input.txt")) return; for(int i=0; i
perror("Cannot open file"); return 0;
} fscanf(f, "%d", &g.n); for(int i=0; i 0) { soct++; hamilton[lan] = 0; printf("Chu trinh Hamilton thu %d: ", soct); InHamilton(g.n+1); } else if(lan < g.n) for(int y=0; y 0 && chuaxet[y]) { hamilton[lan] = y; chuaxet[y] = 0; CTHamilton(lan+1); chuaxet[y] = 1; } } void DDHamilton(int lan) { if(lan == g.n) { sodd++; printf("Duong di Hamilton thu %d: ", sodd); InHamilton(g.n); } else if(lan < g.n) for(int y=0; y 0 && chuaxet[y]) { hamilton[lan] = y; chuaxet[y] = 0; DDHamilton(lan+1); chuaxet[y] = 1; } } void InHamilton(int n) { for(int i=0; i", hamilton[i]); printf("%d\n", hamilton[n-1]); }