栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

ACwing寒假每日一题2022打卡 Day 6

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ACwing寒假每日一题2022打卡 Day 6

原题链接:

2005. 马蹄铁 - AcWing题库高质量的算法题库https://www.acwing.com/problem/content/2007/

思路:

直接dfs暴力枚举所有路径然后求最大值就行,唯一麻烦一点的地方就是还得写个check函数判断一下路径是否合法,这题数据范围小,就是练暴力用的,具体细节见代码

Code:

#include 
#include 
#include 
using namespace std;
const int N = 10;
int ans;
int X,Y;
bool st[N][N];
int num[N*N*N];
char g[N][N];
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n;
int res=1;
bool check()
{
    if(res%2) return false;

    for(int i=0;i=res/2;i--)
    if(num[i]!=2) return false;

    return true;
}

void dfs(int x,int y)
{
    if(x==X&&y==Y)
    {
        if(check())
        {
            ans=max(ans,res);
        }
        return;
    }

    for(int i=0;i<4;i++)
    {
        int a=x+dx[i],b=y+dy[i];
        if(st[a][b]||a<0||b<0||a>=n||b>=n) continue;
        st[a][b]=true;
        //cout<>n;
    for(int i=0;i>g[i][j];

    if(g[0][0]=='(') num[0]=1;
    else
    num[0]=2;

    st[0][0]=true;

    for(int i=0;i 

作者:机械之忍
链接:https://www.acwing.com/activity/content/code/content/2257351/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/702830.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号