HDU - 2614 Beat
2016-07-26 15:25
465 查看
巨坑!
题目:
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
且不说Hint写的是错的,因为这并没有影响我理解题意。
但是!
对角线根本就没有意义,然后看那三组输入示例,我下意识的以为输入的对角线应该都是0吧。
10点39第一次提交就是Wrong Answer,后面一直是错的,然后中午睡了会,下午继续分析,
代码被化简到了非常恐怖的地步,然而还是Wrong Answer。
然后和同学讨论题意,看是不是我理解错了。但是没有!题意就是我理解的那样!
讨论的过程中无意间想到,输入的对角线不一定都是0,这个地方会导致我的计算错误。
我的代码是:
之前就是因为main函数里面少了一句list[0][0]=0;
所以就错了。
超级坑爹啊啊啊啊。。。。
当然,这个代码还有点问题,时间代价是正常代码的指数级倍。运行时间是1326 ms
稍作修改即可得到运行时间为62 ms的代码:
题目:
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
Hint: sample one, as we know zty always solve problem 0 by costing 0 minute. So after solving problem 0, he can choose problem 1 and problem 2, because T01 >=0 and T02>=0. But if zty chooses to solve problem 1, he can not solve problem 2, because T12 < T01. So zty can choose solve the problem 2 second, than solve the problem 1.
且不说Hint写的是错的,因为这并没有影响我理解题意。
但是!
对角线根本就没有意义,然后看那三组输入示例,我下意识的以为输入的对角线应该都是0吧。
10点39第一次提交就是Wrong Answer,后面一直是错的,然后中午睡了会,下午继续分析,
代码被化简到了非常恐怖的地步,然而还是Wrong Answer。
然后和同学讨论题意,看是不是我理解错了。但是没有!题意就是我理解的那样!
讨论的过程中无意间想到,输入的对角线不一定都是0,这个地方会导致我的计算错误。
我的代码是:
#include<iostream> using namespace std; int n; int list[17][17]; bool f[17]; int dfs(int a, int b) { f[b] = false; int s = 0; for (int i = 0; i < n; i++)if (f[i] && list[b][i] >= list[a][b] && s < dfs(b, i) + 1)s = dfs(b, i) + 1; f[b] = true; return s; } int main() { while (cin >> n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++)cin >> list[i][j]; f[i] = true; } list[0][0] = 0; cout << dfs(0, 0) + 1 << endl; } return 0; }
之前就是因为main函数里面少了一句list[0][0]=0;
所以就错了。
超级坑爹啊啊啊啊。。。。
当然,这个代码还有点问题,时间代价是正常代码的指数级倍。运行时间是1326 ms
稍作修改即可得到运行时间为62 ms的代码:
#include<iostream> using namespace std; int n; int list[17][17]; bool f[17]; int t; int dfs(int a, int b) { f[b] = false; int s = 0; for (int i = 0; i < n; i++) if (f[i] && list[b][i] >= list[a][b]) { t = dfs(b, i) + 1; if(s<t)s =t; } f[b] = true; return s; } int main() { while (cin >> n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++)cin >> list[i][j]; f[i] = true; } list[0][0] = 0; cout << dfs(0, 0) + 1 << endl; } return 0; }
相关文章推荐
- androidcopy文件
- Android静态安全检测 -> HTTPS敏感数据劫持漏洞
- nodejs、gulp调试工具node-inspector使用
- 泛型相关
- JQuery之CSS选择器
- mac上实现git命令自动补全
- getElementsByTagName
- [转] SQL Server中变量的声明和使用方法
- 内核终端判断,微信?QQ?ipad?IE?移动?Google?opera……
- 转:js中this关键字详解
- mac os 安装 wget
- Oracle 11g安装图文攻略
- Oracle创建datafile,tablefile,role,user随笔
- 20分钟打造你的Bootstrap站点
- Java工程中引用Base64编码解码小记
- mongodb的安装、单主机配置、主从配置、replicaSet副本集配置
- java基础总结_08
- Xcode恢复设置默认字体
- Rails Respond Format 应用
- Java集合之List