HDU 2614 Beat(dfs)
来源:互联网 发布:网络策划 编辑:程序博客网 时间:2024/06/05 05:20
Beat
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1647 Accepted Submission(s): 972
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
题意:T(i,j)表示的是当做完i题然后做j题,j题需要花费的时间,从0题开始做,花费时间0,要求找能解出的最多个数(花费时间是不递减的)
思路:dfs搜索即可
AC代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=16;int g[maxn][maxn];int n;int vis[maxn];int dfs(int i,int cur){ //i表示之前前做的题,cur表示 i对应的时间 int ans=1;for(int j=1;j<n;j++){if(!vis[j] && cur<=g[i][j]){vis[j]=1;ans=max(ans,dfs(j,g[i][j])+1);vis[j]=0;}}return ans;}int main(){while(scanf("%d",&n)==1){memset(g,-1,sizeof(g));memset(vis,0,sizeof(vis));for(int i=0;i<n;i++) for(int j=0;j<n;j++) scanf("%d",&g[i][j]); int ans=dfs(0,0); printf("%d\n",ans);}return 0;}
1 0
- HDU 2614 Beat(dfs)
- HDU 2614 Beat (DFS)
- HDU 2614 Beat(DFS)
- HDU 2614 Beat(dfs)
- hdu 2614 Beat (dfs)
- HDU 2614 Beat (dfs)
- HDU 2614 Beat (DFS)
- HDU 2614 Beat(dfs+回溯)
- 【DFS】 HDU 2614 Beat 水
- hdu 2614 BEAT 回溯的dfs
- HDOJ 题目2614 Beat(DFS)
- hdu(2614) Beat
- hdu 2614 Beat
- HDU 2614 Beat
- hdu 2614 Beat
- HDU 2614 Beat
- hdu 2614 beat
- hdu 2614 Beat
- java内部类使用场景
- PHP适配器模式
- 嵌入式学ARM体系总结(一)
- 科克曼女生问题
- 斗鱼应用(V2.4.6.1)安装在不同型号的机器上,所呈现的图标不一致的原因
- HDU 2614 Beat(dfs)
- -bash: command is not found
- 多行文字居中
- 购物单
- Spring配置中<bean>的id和name属性区别
- pygame.surfarray.array3d()的作用
- 一个简单的SpringMVC项目到底需要哪些JAR包(文章最后附上最简单的方法导相关包)
- 47. Permutations II
- 深度学习(Deep Learning)从零基础达到入门级水平