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 }
时间: 2024-09-29 09:15:34

HDU-2614的相关文章

DFS HDU 2614

很水的.但是wa了很多遍,因为写num[1][1]... 改成0之后就过了...虽然不知道为什么... Beat Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 659    Accepted Submission(s): 415 Problem Description Zty is a man that always full of

hdu 2614 beat

这题最难得地方在于把题目看懂,简单的dfs,没什么好说的 #include<iostream> #include<cstring> #define maxn 15+1 using namespace std; int maxx; int mapp[maxn][maxn]; int visit[maxn]; int n; void dfs(int x,int time,int num) { for(int i=1;i<=n;i++) { if(!visit[i]&&am

HDU 2614 Beat(DFS)

题目链接 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 solvea problem that is easy than problem he had solved. Now yifenfe

HDU 2614 Beat 深搜DFS

这道题目还是比较水的,但是题意理解确实费了半天劲,没办法 谁让自己是英渣呢! 题目大意: 猪脚要解决问题, 他有个习惯,每次只解决比之前解决过的问题的难度要大. 他给我们一个矩阵  矩阵的 i 行 j 列表示 解决完第 i 个问题后再解决第 j 个问题 花费时间为 T[i][j] 也就是 题目的难度. 并且他是从第0个问题开始解决的,第0个问题花费的时间为 0 下面是代码 : 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include&l

I - Beat HDU - 2614 DFS

Beat Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2184    Accepted Submission(s): 1256 Problem Description Zty is a man that always full of enthusiasm. He wants to solve every kind of difficu

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

[HDU 2553]--N皇后问题(回溯)/N皇后问题的分析

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2553 N皇后问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上.你的任务是,对于给定的N,求出有多少种合法

HDU 1426 Sudoku Killer(dfs 解数独)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1426 Sudoku Killer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9804    Accepted Submission(s): 2944 Problem Description 自从2006年3月10日至11日的首届数独世界