hdu2614 Beat(简单dfs)

本文解析了HDU 2614题目,该题要求通过深度优先搜索策略找到在遵循难度递增规则的情况下可以完成的最大题目数量。文章提供了完整的C++代码实现,并介绍了如何从起始题目出发进行搜索并更新最大值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


http://acm.hdu.edu.cn/showproblem.php?pid=2614

题意:给你一个二维数组,Map[i][j]代表做完i题做j题的难度。这个人做题不愿意做比上一道简单的,求他最多能做几道题。


思路:题中说从第0到题开始做,所以从0开始搜索,搜索过程中统计最大值即可。


#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>

using namespace std;

typedef __int64 LL;

const int N = 20;
const int INF = 0x3f3f3f3f;

int Map[N][N], vis[N], ans, n;

void dfs(int last, int num, int w)
{
    ans = max(ans, num);
    for(int i = 0; i < n; i++)
    {
        if(vis[i] == 1 || Map[last][i] < w) continue;
        vis[i] = 1;
        dfs(i, num+1, Map[last][i]);
        vis[i] = 0;
    }
}

int main()
{
   // freopen("in.txt", "r", stdin);
    while(~scanf("%d", &n))
    {
        ans = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                scanf("%d", &Map[i][j]);
            }
        }
        memset(vis, 0, sizeof(vis));
        vis[0] = 1;
        dfs(0, 1, 0);
        printf("%d\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值