• POJ 1154


    #include<iostream>
    #include<stdio.h>
    #define MAXN 20
    using namespace std;
    
    int DFS(int i,int j,int len,int r,int c);
    bool key[26];
    char a[MAXN][MAXN];
    //bool bool_lean[MAXN][MAXN];
    int main()
    {
        //freopen("acm.acm","r",stdin);
        int i;
        int j;
        int r;
        int c;
        cin>>r>>c;
    //    memset(bool_lean,false,sizeof(bool_lean));
        for(i = 0; i < r; ++ i)
        {
            for(j = 0; j < c; ++ j)
            {
                cin>>a[i][j];
            }
        }
        key[a[0][0]-'A'] = true;
        cout<<DFS(0,0,1,r,c)<<endl;
    }
    
    int DFS(int i,int j,int len,int r,int c)
    {
        int tem;
        tem = len;
        int max = 0;
        if(i > 0)
        {
            if(!key[a[i-1][j] - 'A'])
            {
                key[a[i-1][j] - 'A'] = true;
            //    bool_lean[i-1][j] = true;
                len = DFS(i-1,j,len+1,r,c);
                key[a[i-1][j] - 'A'] = false;
            //    bool_lean[i-1][j] = false;
                if(len > max)
                    max = len;
                len = tem;
            }
        
        }
        if(i < r-1)
        {
            if(!key[a[i+1][j] - 'A'])
            {
                key[a[i+1][j] - 'A'] = true;
            //    bool_lean[i+1][j] = true;
                len = DFS(i+1,j,len+1,r,c);
                key[a[i+1][j] - 'A'] = false;
            //    bool_lean[i+1][j] = false;
                if(len > max)
                    max = len;
                len = tem;
            }
    
        }
        if(j > 0)
        {
            if(!key[a[i][j-1] - 'A'])
            {
                key[a[i][j-1] - 'A'] = true;
            //    bool_lean[i][j-1] = true;
                len = DFS(i,j-1,len+1,r,c);
                key[a[i][j-1] - 'A'] = false;
            //    bool_lean[i][j-1] = false;
                if(len>max)
                    max = len;
                len = tem;
            }
        }
        if(j < c-1)
        {
            if(!key[a[i][j+1] - 'A'])
            {
                key[a[i][j+1] - 'A'] = true;
        //        bool_lean[i][j+1] = true;
                len = DFS(i,j+1,len+1,r,c);
                key[a[i][j+1] - 'A'] = false;
        //        bool_lean[i][j+1] = false;
                if(len>max)
                    max = len;
                len = tem;
            }
        }    
        if(len > max)
            max = len;
        return max;
    }

    关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

    技术网站地址: vmfor.com

  • 相关阅读:
    bzoj3688 折线统计
    bzoj3678 wangxz与OJ
    「6月雅礼集训 2017 Day8」route
    「6月雅礼集训 2017 Day8」gcd
    [ SHELL编程 ] 编程常用的ORACLE相关命令
    Oracle数据库备份/导入工具
    Oracle数据文件迁移到裸设备
    Oracle数据文件转移操作
    Oracle重建表空间操作实例
    Linux性能测试分析命令_sar
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4563309.html
Copyright © 2020-2023  润新知