50分WA求助

P1434 [SHOI2002] 滑雪

ChengZe @ 2018-12-21 20:37:47

50分WA求助

#include <bits/stdc++.h>
using namespace std;
struct wow{
    int x,y,num;
}b[101*101];
int dx[4]{-1,0,0,1},dy[4]{0,1,-1,0};
bool cmp(wow aa,wow bb){
    return aa.num<bb.num;
}

int main()
{
    int n,m,now=0;
    //cin>>m>>n;改成这个60分,不改50分
    cin>>n>>m; 
    int a[n+2][m+2],f[n+2][m+2];
    for(int i=0;i<=n+1;i++)
    for(int j=0;j<=m+1;j++)f[i][j]=1;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++){
        cin>>a[i][j];
        now++;
        b[now].num=a[i][j];
        b[now].x=i;
        b[now].y=j;
    }
    sort(b+1,b+now+1,cmp);
    for(int i=1;i<=now;i++){
        for(int j=0;j<4;j++)if(a[b[i].x][b[i].y]>a[b[i].x+dx[j]][b[i].y+dy[j]]&&b[i].x+dx[j]>0&&b[i].x+dx[j]<=n&&b[i].y+dy[j]>=0&&b[i].y+dy[j]<=m)f[b[i].x][b[i].y]=max(f[b[i].x+dx[j]][b[i].y+dy[j]]+1,f[b[i].x][b[i].y]);
    //cout<<a[b[i].x][b[i].y]<<' '<<f[b[i].x][b[i].y]<<endl;
    }
    int ans=0;
    //for(int i=1;i<=n;i++){
    //  for(int j=1;j<=m;j++)cout<<setw(3)<<f[i][j]<<' ';
    //  cout<<endl;
    //}
    for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)ans=max(ans,f[i][j]);
    cout<<ans;
}

by opened @ 2018-12-21 20:53:40

#include<iostream>
#include<cstdio>
using namespace std; 
const int maxn=110; 
int r,c,dp[maxn][maxn],a[maxn][maxn],ans; 
const int dx[]={0,1,0,-1,0},dy[]={0,0,-1,0,1};
int d(int x,int y){
    if(dp[x][y]) return dp[x][y];
    int z=0;
    for(int i=1;i<=4;i++){
        int xx=x+dx[i],yy=y+dy[i];
        if(xx>=1&&xx<=r&&yy>=1&&yy<=c&&a[xx][yy]>a[x][y]) z=max(z,d(xx,yy));
    }
    return dp[x][y]=z+1;
}
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]);
    for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++) ans=max(ans,d(i,j));
    printf("%d\n",ans);
    return 0;
}

by fuhongjun2018 @ 2018-12-21 21:50:31

@opened 就直接上代码了?


|