70分求助

P1434 [SHOI2002] 滑雪

zwz2010 @ 2024-08-30 15:47:34

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N = 102;
int r,c,t;
int f[N][N],a[N][N],v[3][5] = {{0,0,0,0,0},{0,1,-1,0,0},{0,0,0,1,-1}};

int s(int x,int y){
    if(f[x][y] > 0) return f[x][y];
    f[x][y] = 1;
    for(int u=1;u<=4;u++){
        int nx = x+v[1][u];
        int ny = y+v[2][u];
        if(nx>=1&&nx<=c&&ny>=1&&nx<=r&&a[nx][ny]<a[x][y])  f[x][y] = max(f[x][y],s(nx,ny)+1);
    }
    return f[x][y];
}

int main(){
    scanf("%d%d",&r,&c);
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            scanf("%d",&a[i][j]);
        }
    }
    int ans = -0x3f3f3f3f;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            t = s(i,j);
            f[i][j] = t;
            ans = max(ans,t);
        }
    }
    printf("%d\n",ans);
    return 0;
}

by a11223344 @ 2024-09-10 21:35:17

    if(nx>=1&&ny<=c&&ny>=1&&nx<=r&&a[nx][ny]<a[x][y])  f[x][y] = max(f[x][y],s(nx,ny)+1);

|