Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴上代码

Posted by 20152480225 at 2017-03-10 20:15:23 on Problem 1088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 100+4;
int Map[maxn][maxn];
int d[maxn][maxn];
int r, c, ans;
int dr[4][2] = {{-1,0}, {0, -1}, {1, 0}, {0, 1}};

int dfs(int x, int y){
    if(d[x][y] != 0){
        return d[x][y];
    }
    d[x][y] = 1;
    for (int i = 0; i < 4; ++i){
        int mx = x + dr[i][0], my = y + dr[i][1];
        if (mx >= 0 && my >= 0 && mx < r && my < c && Map[mx][my] < Map[x][y]){
            d[x][y] = max(d[x][y], dfs(mx, my) + 1);
        }
    }
    ans = max(ans, d[x][y]);
    return d[x][y];
}

int main(){
    while(~scanf("%d%d", &r, &c)){
        for (int i = 0; i < r; ++i){
            for (int j = 0; j < c; ++j){
                scanf("%d", &Map[i][j]);
            }
        }
        memset(d, 0, sizeof d );
        ans = 1;
        for (int i = 0; i < r; ++i){
            for (int j = 0; j < c; ++j){
                dfs(i , j);
            }
        }
        printf("%d\n", ans);
        //cout << ans << endl;
    }

    return 0;
}
//zzuwenjie

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator