hdu2614: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 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

题意:T[i][j]表示处理完i问题后,处理j问题需要的时间,但是如果我处理了i问题,现在处理j问题,那么如果我再处理k问题的要求是必须

T[i][j]>=T[j][k]

搜索一遍即可
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;

int map[20][20];
int n,vis[20],maxn;

void dfs(int now,int len,int tim)
{
    maxn = max(maxn,len);
    if(maxn == n)
        return ;
    for(int i = 1; i<n; i++)
    {
        if(vis[i])
            continue;
        if(map[now][i]>=tim)
        {
            vis[i] = 1;
            dfs(i,len+1,map[now][i]);
            vis[i] = 0;
        }
    }
}

int main()
{
    int i,j;
    while(~scanf("%d",&n))
    {
        for(i = 0; i<n; i++)
        {
            for(j = 0; j<n; j++)
                scanf("%d",&map[i][j]);
        }
        maxn = 0;
        memset(vis,0,sizeof(vis));
        vis[0] = 1;
        for(int i = 1; i<n; i++)
        {
            vis[i] = 1;
            dfs(i,2,map[0][i]);
            vis[i] = 0;
        }
        printf("%d\n",maxn);
    }

    return 0;
}
时间: 2024-10-11 13:08:14

hdu2614:Beat(dfs)的相关文章

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

hdu2614 Beat

题意: 有n个问题. 给出你解决完第i个问题之后解决j问题所花的时间,花的时间越多表示难度越大,每次只能解决难度大于或等于上个题难度的问题.问你最多能解决多少问题. 他妈的,第一次做想半天想不出来如何设计递归函数.真是考验智商... 不过最后还是看了别人题解之后才顿悟 代码: #include <iostream> #include <cstdio> #include <cstring> using namespace std; int flag[10001]; int

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 2614 Beat 深搜DFS

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

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 4068 dfs枚举

SanguoSHA Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 944    Accepted Submission(s): 520 Problem Description Sanguosha has a singled version. Two players each select N heroes and start fight

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 difficu

HDU1027 Ignatius and the Princess II 【next_permutation】【DFS】

Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4571    Accepted Submission(s): 2733 Problem Description Now our hero finds the door to the BEelzebub feng5166. He o

dfs第二遍重学

---恢复内容开始--- 1.先上个基础的全排列 #include<iostream> #include<cstring> using namespace std; const int maxn=1e3; int vis[maxn]; int p[maxn]; int n; int t=0; void dfs(int x) { if(x==n+1) { for(int i=1;i<=n;i++) cout<<p[i]<<" "; c