HDU-2614

Beat

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1711    Accepted Submission(s): 1001


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

 

题意比较难懂,浪费了一些时间,可能是hint有一些误导,导致看得并不顺畅。

简单来说就是第0题发费0分钟,以后的每一题时间都不得小于上一题。

即:T[i][j]>=T[j][k]。

 

由此,dfs可得。

 

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 bool vis[20];
 5 int n,MAX;
 6 int mp[20][20];
 7 
 8 void dfs(int now,int len,int cnt){
 9     MAX=max(len,MAX);
10     if(MAX==n)
11     return ;
12     for(int i=1;i<n;i++){
13         if(vis[i]==1)
14         continue;
15         if(mp[now][i]>=cnt){
16             vis[i]=1;
17             dfs(i,len+1,mp[now][i]);
18             vis[i]=0;
19         }
20     }
21 }
22 
23 int main(){
24     while(cin>>n){
25         for(int i=0;i<n;i++){
26             for(int j=0;j<n;j++){
27                 cin>>mp[i][j];
28             }
29         }
30         MAX=0;
31         memset(vis,0,sizeof(vis));
32         vis[0]=1;
33         for(int i=1;i<n;i++){
34             vis[i]=1;
35             dfs(i,2,mp[0][i]);
36             vis[i]=0;
37         }
38         cout<<MAX<<endl;
39     }
40     return 0;
41 }

 

posted @ 2017-04-20 20:32  Kiven#5197  阅读(243)  评论(0编辑  收藏  举报