美文网首页
poj3620 深搜

poj3620 深搜

作者: 暖昼氤氲 | 来源:发表于2019-12-02 16:38 被阅读0次
     /*
    Time:2019.12.2 
    Author: Goven
    type:深搜 
    err:RUNTIME ERR
    ref:
    */
    #include<iostream>
    #include<cstring>
    using namespace std;
    
    int g[105][105];
    bool visit[105][105];
    int r[10005], c[10005];//RUNTIME ERR:数组开太小了 
    
    int dfs(int r, int c) {
        if (visit[r][c] == true || g[r][c] == 0) return 0;
        visit[r][c] = true;
        return 1 + dfs(r + 1, c) + dfs(r - 1, c) + dfs(r, c + 1) + dfs(r, c - 1); //r\c边界不需要另外判断 
    }
    int main()
    {
        memset(g, 0, sizeof(g));
        memset(visit, false, sizeof(visit));
        
        int n, m, k;
        cin >> n >> m >> k;
        for (int i = 0; i < k; i++) {
            cin >> r[i] >> c[i];
            g[r[i]][c[i]] = 1;
        }
        int res = 0;
        for (int i = 0; i < k; i++) {
            res = max(res, dfs(r[i], c[i]));
        }
        cout << res << endl;
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:poj3620 深搜

          本文链接:https://www.haomeiwen.com/subject/kksfgctx.html