【SHOI2002】【Luogu1434】滑雪

problem

solution

codes

//f[i][j]:以(i,j)为终点的最长路是是多少
//f[i][j] = f(它四周的比他高的方块的最长路)+1
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 110;
int r, c, a[maxn][maxn], f[maxn][maxn], ans;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
bool inside(int x, int y){return x>=1&&x<=r&&y>=1&&y<=c;}
int dp(int x, int y){
    if(f[x][y])return f[x][y];
    int res = 0;
    for(int i = 0; i < 4; i++){
        int nx = x+dx[i], ny = y+dy[i];
        if(inside(nx,ny)&&a[nx][ny]>a[x][y]){
            res = max(res,dp(nx,ny));
        }
    }
    return f[x][y]=res+1;//我竟然因为没有更新f[x][y]导致第二个点没过。。
}
int main(){
    ios::sync_with_stdio(false);
    cin>>r>>c;
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
            cin>>a[i][j];
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
            ans = max(ans,dp(i,j));
    cout<<ans;
    return 0;
}
posted @ 2018-05-26 22:11  gwj1139177410  阅读(114)  评论(0编辑  收藏  举报
选择