30分求助

P1434 [SHOI2002] 滑雪

a253774060 @ 2018-07-31 17:41:21

只对了第2、3、4个点

#include<cstdio>
#include<algorithm>

namespace io{
    int get(){
        int num=0;
        char c=getchar();
        while(c<'0' || c>'9') c=getchar();
        while(c>='0' && c<='9'){
            num=(num<<3)+(num<<1)+(c-'0');
            c=getchar();
        }
        return num;
    }
}

struct Node{
    int x,y,h,max;
}node[10001];

bool comp(Node a,Node b){return a.h<b.h;}

inline int abs(int a){return a<0? -a:a;}

bool link(Node a,Node b){return abs(a.x-b.x)<=1 && abs(a.y-b.y)<=1? 1:0;}

int main(){
    int t,idx=0,ans=0;
    int r=io::get();
    int c=io::get();
    for(int i=0;i<r;++i){
        for(int j=0;j<c;++j){
            node[idx].x=i;
            node[idx].y=j;
            node[idx].max=1;
            node[idx++].h=io::get();
        }
    }
    std::sort(node,node+idx,comp);

    for(int i=1;i<idx;++i){
        for(int j=0;j<i;++j){
            if(link(node[i],node[j]) && node[i].max<(t=node[j].max+1)) node[i].max=t;
        }
    }

    for(int i=0;i<idx;++i){
        if(node[i].max>ans) ans=node[i].max;
    }
    printf("%d",ans);
}

|