Problem Description
Zty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solve
a problem that is easy than problem he had solved. Now yifenfei give him n difficulty problems, and tell him their relative time to solve it after solving the other one.
You should help zty to find a order of solving problems to solve more difficulty problem.
You may sure zty first solve the problem 0 by costing 0 minute. Zty always choose cost more or equal time’s problem to solve.
Input
The input contains multiple test cases.
Each test case include, first one integer n ( 2< n < 15).express the number of problem.
Than n lines, each line include n integer Tij ( 0<=Tij<10), the i’s row and j’s col integer Tij express after solving the problem i, will cost Tij minute to solve the problem j.
Output
For each test case output the maximum number of problem zty can solved.
Sample Input
3 0 0 0 1 0 1 1 0 0 3 0 2 2 1 0 1 1 1 0 5 0 1 2 3 1 0 0 2 3 1 0 0 0 3 1 0 0 0 0 2 0 0 0 0 0
Sample Output
3 2 4 题意:T[i][j]表示处理完i问题后,处理j问题需要的时间,但是如果我处理了i问题,现在处理j问题,那么如果我再处理k问题的要求是必须 T[i][j]>=T[j][k] 搜索一遍即可#include <stdio.h> #include <string.h> #include <queue> #include <algorithm> using namespace std; int map[20][20]; int n,vis[20],maxn; void dfs(int now,int len,int tim) { maxn = max(maxn,len); if(maxn == n) return ; for(int i = 1; i<n; i++) { if(vis[i]) continue; if(map[now][i]>=tim) { vis[i] = 1; dfs(i,len+1,map[now][i]); vis[i] = 0; } } } int main() { int i,j; while(~scanf("%d",&n)) { for(i = 0; i<n; i++) { for(j = 0; j<n; j++) scanf("%d",&map[i][j]); } maxn = 0; memset(vis,0,sizeof(vis)); vis[0] = 1; for(int i = 1; i<n; i++) { vis[i] = 1; dfs(i,2,map[0][i]); vis[i] = 0; } printf("%d\n",maxn); } return 0; }