大佬求助!!!

P1434 [SHOI2002] 滑雪

judgejudge @ 2019-02-23 10:54:06

#include <iostream>
using namespace std;
int a[10000][10000];
int f[10000][10000];
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++){
            cout<<f[i][j]<<" ";
            if(maxl<f[i][j])maxl=f[i][j];
        }
        cout<<endl;
    }
    cout<<maxl;
}

by 7KByte @ 2019-02-23 11:03:29

您的数组开太大了


by judgejudge @ 2019-02-23 19:04:02

@Gang_Leader 我把数组调小一点,还是不行


by judgejudge @ 2019-02-23 19:05:13

@Gang_Leader


|