2016-07-10 Problem Solving►UVa UVa 291 - The House Of Santa Claus Contents 1. Problem2. Solution3. Code Problem中文網址 Solution直接對每個點做 DFS ,用 used[][] 記錄每條邊的使用狀況和順序,最後印出來即可。 CodeUVa 291123456789101112131415161718192021222324252627282930313233343536#include<cstdio>const int adjList[6][5] = { {},{ 2, 3, 5 }, { 1, 3, 5 }, { 1, 2, 4, 5 }, { 3, 5 }, { 1, 2, 3, 4 } };int order[9];bool used[6][6];void solve(int pre, int n){ if (n == 9) { for (int i = 0; i < 9; i++) printf("%d", order[i]); putchar('\n'); } else { for (int j = 0; adjList[pre][j]; j++) { if (!used[pre][adjList[pre][j]]) { used[adjList[pre][j]][pre] = used[pre][adjList[pre][j]] = true; order[n] = adjList[pre][j]; solve(adjList[pre][j], n + 1); used[adjList[pre][j]][pre] = used[pre][adjList[pre][j]] = false; } } }}int main(){ order[0] = 1; solve(1, 1); return 0;} Newer UVa 409 - Excuses, Excuses! Older UVa 131 - The Psychic Poker Player