HDOJ 2614 Beat
来源:互联网 发布:八实万是网络传销吗 编辑:程序博客网 时间:2024/06/06 05:01
Beat
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.
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.
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
30 0 01 0 11 0 030 2 21 0 11 1 050 1 2 3 10 0 2 3 10 0 0 3 10 0 0 0 20 0 0 0 0
Sample Output
324
解题思路:DFS,利用辅助数组标记问题是否已经被解决。注意要将T00手动设置为0。
代码如下:
#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn = 16;int problem[maxn][maxn];bool solved[maxn];int ans;int n;void dfs(int nth,int dep,int time){ for(int i = 0;i < n;i++){ if(solved[i] || problem[nth][i] < time) continue; solved[i] = 1; dfs(i,dep + 1,problem[nth][i]); solved[i] = 0; } ans = max(ans,dep);}int main(){ while(scanf("%d",&n) != EOF){ for(int i = 0;i < n;i++){ for(int j = 0;j < n;j++){ scanf("%d",&problem[i][j]); } } problem[0][0] = 0; ans = 0; memset(solved,0,sizeof(solved)); solved[0] = 1; dfs(0,1,0); printf("%d\n",ans); } return 0;}
0 0
- HDOJ 2614 Beat
- HDOJ 2614 Beat
- HDOJ Beat
- HDOJ 题目2614 Beat(DFS)
- HDOJ Beat (DFS)
- HDOJ 1194 Beat the Spread!
- HDOJ 1194 Beat the Spread!
- HDOJ 1194 Beat the Spread!
- hdoj.1194 Beat the Spread! 20140815
- hdoj 1194 Beat the Spread!(数学题)
- hdu(2614) Beat
- HDU 2614 Beat (dfs)
- hdu 2614 Beat
- HDU 2614 Beat
- hdu 2614 Beat
- HDU 2614 Beat
- hdu 2614 beat
- HDU 2614 Beat (DFS)
- B树与B+树的区别
- 如何在vs中链接vc6的运行时库
- HDU Problem 5363 Key set 【快速幂】
- http状态码详解
- struts2中获取web资源小结
- HDOJ 2614 Beat
- Java NIO 系列教程
- WEB前端animation和鼠标hover事件属性改变问题。
- With Encryption
- spring tool suite安装不进去
- C语言的类型,字节,还有转义字符0728
- [Cloud Computing]Mechanisms: Virtual Appliance
- UVA1584 UVALive3225 Circular Sequence
- what does “static int function(…) __acquires(..) __releases(…){” mean?