题目传送门
/*
题意:处理完i问题后去处理j问题,要满足a[i][j] <= a[j][k],问最多能有多少问题可以解决
DFS简单题:以每次处理的问题作为过程(即行数),最多能解决n个问题,相同的问题(行数)不再考虑
详细解释:http://blog.csdn.net/libin56842/article/details/41909429
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
const int MAXN = + ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN];
int used[MAXN];
int n;
int ans;
void DFS(int s, int cost, int cnt)
{
ans = max (ans, cnt);
if (cnt == n) return ;
for (int k=; k<=n; ++k)
{
if (a[s][k] >= cost && !used[k])
{
used[k] = ;
DFS (k, a[s][k], cnt+);
used[k] = ;
}
}
}
int main(void) //HDOJ 2614 Beat
{
//freopen ("N.in", "r", stdin);
while (~scanf ("%d", &n))
{
memset (used, , sizeof (used));
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
scanf ("%d", &a[i][j]);
}
}
ans = -; used[] = ;
for (int i=; i<=n; ++i)
{
used[i] = ;
DFS (i, a[][i], );
used[i] = ;
}
printf ("%d\n", ans);
}
return ;
}