巨佬神犇们请点击!!!

P1434 [SHOI2002] 滑雪

judgejudge @ 2019-02-24 12:53:01

#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 12:56:02

和题解对比那个?!


by aminoas @ 2019-02-24 12:58:21

把函数改成inline,再加上快读,可以避免T第二个点。


by aminoas @ 2019-02-24 12:58:42

@judgejudge


by judgejudge @ 2019-02-24 13:04:24

@2018J1605 可以给详细一点吗?


by _stellar @ 2019-02-24 13:04:39

记忆化搜索


by aminoas @ 2019-02-24 13:07:07

@judgejudge

貌似记忆化不行,但是贪心好像也会WA


by csdfret @ 2019-02-24 13:07:37

加个记忆化


by Stay_Hungry @ 2019-02-24 13:24:27

一遍BFS走全图,利用queue队列以及另外一个二维数组记录最长长度


by aminoas @ 2019-02-24 13:37:41

如果我说我一个橙名只会深搜不会广搜你们信吗?


by judgejudge @ 2019-02-24 15:53:26

@2018J1605 me too


| 下一页