题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2614
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
const int maxn = 20;
int n, Ans;
int Map[maxn][maxn];
int ans[maxn];
bool vis[maxn];
void DFS(int x, int Size, int cost)
{
Ans = max(Size, Ans);
for(int i = 0; i < n; i++)
{
if(vis[i]) continue;
if(Map[x][i] >= cost)
{
vis[i] = 1;
DFS(i, Size + 1, Map[x][i]);
vis[i] = 0;
}
}
}
int main()
{
while(cin >> n)
{
Ans = 0;
memset(vis, 0, sizeof(vis));
memset(ans, 0, sizeof(ans));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%d", &Map[i][j]);
}
}
vis[0] = 1;
DFS(0, 1, 0);
cout << Ans << endl;
}
return 0;
}