40pts(样例没过)求调

P1434 [SHOI2002] 滑雪

mysterys @ 2023-02-11 12:03:11

```cpp #include<bits/stdc++.h> using namespace std; int dx[5]={0,-1,0,1,0},dy[5]={0,0,1,0,-1}; long r,c,i,j,p,t,ans; long m[101][101],f[101][101]; int search(int x,int y) { int i,t,tmp,nx,ny; if(f[x][y]>0) { return (f[x][y]); } t=1; for(i=1;i<=4;i++) { nx=x+dx[i]; ny=y+dy[i]; if((nx>=1)&&(nx<=r)&&(ny>=1)&&(ny<=c)&&(m[x][y]<m[nx][ny])) { tmp=search(nx,ny)+1; if(tmp>t) t=tmp; } f[x][y]=t; return (t); } } int main() { cin>>r>>c; ans=0; for(i=1;i<=r;i++) for(j=1;j<=c;j++) cin>>m[i][j]; for(i=1;i<=r;i++) { for(j=1;j<=c;j++) { t=search(i,j); f[i][j]=t; if(t>ans) ans=t; } } cout<<ans; return 0; } ```

by A_Learning_Hornet @ 2023-02-11 12:26:01

看一下我这个,评测了,100分AC。

#include<bits/stdc++.h>
using namespace std;int x[5]={0,-1,0,1,0},y[5]={0,0,1,0,-1},r,c,i,j,p,t,n=0,m[101][101],f[101][101];int se(int,int);
int main(){
    cin>>r>>c;
    for(i=1;i<=r;i++)
        for(j=1;j<=c;j++)
            cin>>m[i][j];
    for(i=1;i<=r;i++)
        for(j=1;j<=c;j++){
            t=se(i,j);f[i][j]=t;
            if(t>n)n=t;
        }
    cout<<n;
}
int se(int l,int k){
    int i,t=1,e,b,d;
    if(f[l][k]>0)return(f[l][k]);
    for(i=1;i<=4;i++){
        b=l+x[i];d=k+y[i];
        if((b>0)&&(b<=r)&&(d>0)&&(d<=c)&&(m[l][k]<m[b][d])){
            e=se(b,d)+1;
            if(e>t)t=e;
        }
    }
    f[l][k]=t;
    return t;
}

by mysterys @ 2023-02-11 17:48:03

@Dark1Bunting8 thx


|