首页 > 其他 > 详细

HDU-2614

时间:2017-04-20 20:46:29      阅读:248      评论:0      收藏:0      [点我收藏+]

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 }

 

HDU-2614

原文:http://www.cnblogs.com/Kiven5197/p/6740664.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!