zoukankan      html  css  js  c++  java
  • poj1154

    深搜

    简单题

    View Code
    #include <iostream>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cstdio>
    using namespace std;

    #define maxn 25

    int n, m;
    char map[maxn][maxn];
    bool vis[30];
    int ans;
    int dir[4][2] =
    {
    {
    0, 1 },
    {
    1, 0 },
    {
    -1, 0 },
    {
    0, -1 } };

    bool ok(int x, int y)
    {
    if (x < 0 || y < 0 || x >= n || y >= m)
    return false;
    return !vis[map[x][y] - 'A'];
    }

    void dfs(int x, int y, int step)
    {
    ans
    = max(ans, step);
    vis[map[x][y]
    - 'A'] = true;
    for (int i = 0; i < 4; i++)
    if (ok(x + dir[i][0], y + dir[i][1]))
    {
    dfs(x
    + dir[i][0], y + dir[i][1], step + 1);
    }
    vis[map[x][y]
    - 'A'] = false;
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    memset(vis, 0, sizeof(vis));
    scanf(
    "%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    scanf(
    "%s", map[i]);
    ans
    = 1;
    dfs(
    0, 0, 1);
    printf(
    "%d\n", ans);
    return 0;
    }
  • 相关阅读:
    ssh免密登录
    jdk安装
    jq选择器
    使用<button></button>标签
    mysql连接字符串
    如何把maven项目转成web项目
    pl/sql连接远程oracle
    Oracle 存储过程
    SQL Server存储过程
    MySQL存储过程
  • 原文地址:https://www.cnblogs.com/rainydays/p/2158586.html
Copyright © 2011-2022 走看看