大佬求助!!!

P1434 [SHOI2002] 滑雪

judgejudge @ 2019-02-24 07:13:21

#include <iostream>
using namespace std;
int a[101][101];
int f[101][101];
int n,m;
int dp(int s1,int s2){
    int i,j;
    if(s1>=1&&s1<=n&&s2>=1&&s2<=m){
        if(a[s1-1][s2]<a[s1][s2]){
            f[s1-1][s2]=max(f[s1-1][s2],f[s1][s2]+1);
            dp(s1-1,s2);
        }
        if(a[s1+1][s2]<a[s1][s2]){
            f[s1+1][s2]=max(f[s1+1][s2],f[s1][s2]+1);
            dp(s1+1,s2);
        }
        if(a[s1][s2-1]<a[s1][s2]){
            f[s1][s2-1]=max(f[s1][s2-1],f[s1][s2]+1);
            dp(s1,s2-1);
        }
        if(a[s1][s2+1]<a[s1][s2]){
            f[s1][s2+1]=max(f[s1][s2+1],f[s1][s2]+1);
            dp(s1,s2+1);
        }
    }
}
int main(){
    int i,j,k;
    int row,col;
    int maxl=0;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++){
        cin>>a[i][j];
        if(a[i][j]>maxl){
            maxl=a[i][j];
            row=i;
            col=j;
        }
    }
    maxl=0;
    f[row][col]=1;
    dp(row,col);
    for(i=1;i<=n;i++)
    for(j=1;j<=m;j++)
    if(maxl<f[i][j])maxl=f[i][j];
    cout<<maxl;
    return 0;
}

by aminoas @ 2019-02-24 07:31:08

这题数据范围100,感觉用搜索会爆...


by judgejudge @ 2019-02-24 08:07:27

@2018J1605 那怎么修改呢?蒟蒻求助


by aminoas @ 2019-02-24 08:10:51

我也不知道,正在努力中...


by judgejudge @ 2019-02-24 08:14:13

@2018J1605 好吧,谢谢dalao qwq


by Times_New_man @ 2019-03-09 10:13:16

@judgejudge 用记忆化搜索


|