题目链接

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

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.

 
题解:题目说的是zty做题目有一个奇怪的习惯,不会去做那些花费时间少于已经做过的题目所花时间的题,也就是说不会做更简单的题。在题目中,就是搜索的下一个位置的数字不能比之前的小。zty总是从第一题开始做起。
 
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
//#define LOCAL
int pro[][],maxx,n;
bool vis[];
void dfs(int p,int las,int cnt)
{
int flag=;
for(int i=; i<=n; i++)
{
if(!vis[i]&&(pro[p][i]>=las))
{
vis[i]=;
dfs(i,pro[p][i],cnt+);
vis[i]=;
flag=;
}
}
if(!flag)if(cnt>maxx)maxx=cnt;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
//Start
while(cin>>n)
{
maxx=;
memset(pro,,sizeof pro);
memset(vis,,sizeof vis);
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
cin>>pro[i][j];
vis[]=;
dfs(,,);
printf("%d\n",maxx);
}
return ;
}

HDU 2614 Beat(DFS)的更多相关文章

  1. HDU 2614 Beat 深搜DFS

    这道题目还是比较水的,但是题意理解确实费了半天劲,没办法 谁让自己是英渣呢! 题目大意: 猪脚要解决问题, 他有个习惯,每次只解决比之前解决过的问题的难度要大. 他给我们一个矩阵  矩阵的 i 行 j ...

  2. DFS HDOJ 2614 Beat

    题目传送门 /* 题意:处理完i问题后去处理j问题,要满足a[i][j] <= a[j][k],问最多能有多少问题可以解决 DFS简单题:以每次处理的问题作为过程(即行数),最多能解决n个问题, ...

  3. HDU.5692 Snacks ( DFS序 线段树维护最大值 )

    HDU.5692 Snacks ( DFS序 线段树维护最大值 ) 题意分析 给出一颗树,节点标号为0-n,每个节点有一定权值,并且规定0号为根节点.有两种操作:操作一为询问,给出一个节点x,求从0号 ...

  4. HDU - 2614 dfs

    思路:记录当前用的最大时间即刚解决的问题花费的时间,下一个应该做的题的时间必须大于等于刚才的. AC代码 #include <cstdio> #include <cmath> ...

  5. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  6. hdu 4499 Cannon dfs

    Cannon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4499 D ...

  7. hdu 1175 连连看 DFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175 解题思路:从出发点开始DFS.出发点与终点中间只能通过0相连,或者直接相连,判断能否找出这样的路 ...

  8. HDU 5547 Sudoku(DFS)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5547 题目: Sudoku Time Limit: 3000/1000 MS (Java/Others ...

  9. F - Auxiliary Set HDU - 5927 (dfs判断lca)

    题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...

随机推荐

  1. emacs 使用教程

    http://www.cnblogs.com/liuchaogege/p/4464211.html

  2. RubyMine 2016.1 下载 附注册激活码 破解版方法

    注册破解方法: 在要求输入注册的界面选择激活码,然后粘贴以下注册码: 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIj ...

  3. fpga之显示字符串

    //必须在有效区域下显示颜色才有颜色 显示字符可以在设定一个有效区域内显示 另加两个wire 求出新的x,ymodule vga_fpga( clk,rst_n, vga_b,vga_g,vga_r, ...

  4. HTML form的一些属性(第一版)

    p,li { white-space: pre-wrap } HTML表单属性总结(第一版) 基本格式为:<input type="类型" name="名字[唯一, ...

  5. 关于RDD

    1. transform操作返回的是rdd, action操作返回其它数据类型,可以以此来区分操作类型: 2. Spark懒加载,懒到直到Action操作的时候才会加载数据计算,RDD的create和 ...

  6. Laravel默认使用utf8_unicode_ci 即使数据库是utf8_general_ci

    这样做的后果是,不方便和utf8_general_ci字符串字段进行JOIN查询ON.

  7. markdown 自定义一个锚点

    //自定义锚点 s "m[": function mlink( text ) { var orig = String(text); // Inline content is pos ...

  8. python 之调用Linux shell命令及相关高级应用

    最近根据老大要求,将数据进行同步备份,结合第三方提供的工具.第三方服务其实是有python demo的,本想研究下实际的python sdk搞个demo开发的,但是发现有些组建装起来确实头大,而且本公 ...

  9. i++与++i区别使用

    中心:使用变量自增或者处减使用尽量使用++i与--i,而不要去使用i++与i-- ++i与--i可以做左值也可以做右值,而i++与i--只能做右值. 对于基础类型i++与++i结果相同,但是i++肯定 ...

  10. Linux 服务器系统监控脚本 Shell【转】

    转自: Linux 服务器系统监控脚本 Shell - 今日头条(www.toutiao.com)http://www.toutiao.com/i6373134402163048961/ 本程序在Ce ...