题目:http://acm.hdu.edu.cn/showproblem.php?pid=2614
AC代码(C++):
#include <iostream> #include <queue> #include <algorithm> #define INF 0x3f3f3f3f using namespace std; struct NODE { short x, y, step; }; int n, ans; int map[20][20]; bool vis[20]; void dfs(int cur, int last, int step) { if (step > ans)ans = step; for (int i = 0; i < n; i++) { if (!vis[i] && map[cur][i] >= last) { vis[i] = true; dfs(i, map[cur][i], step + 1); vis[i] = false; } } } int main() { while (cin >> n) { for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)cin >> map[i][j]; ans = 1; memset(vis, false, sizeof(vis)); vis[0] = true; dfs(0, 0, 1); cout << ans << endl; } //system("pause"); }总结: 深搜, 题目给的提示是错的, 无视就好.