hhhwg07 @ 2019-03-12 23:55:47
90分,求救
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
struct node{
int h,x,y;
}t;
struct cmp{
bool operator () (node a,node b){
return a.h>b.h;
}
};
priority_queue<node,vector<node>,cmp> pq;
int r,c;
int dp[102+3][102+3],g[101+3][101+3];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int main(){
memset(dp,-1,sizeof(dp));
cin>>r>>c;
for(int i=1;i<=r;i++){
for(int j=1;j<=r;j++){
cin>>g[i][j];
t.h=g[i][j];
t.x=i;t.y=j;
pq.push(t);
}
}
int ans=-100;
for(;!pq.empty();pq.pop()){
t=pq.top();
dp[t.x][t.y]=1;
int x,y;
for(int i=0;i<4;i++){
x=t.x+dx[i];y=t.y+dy[i];
if(g[x][y]==g[t.x][t.y])continue;
dp[t.x][t.y]=max(dp[x][y]+1,dp[t.x][t.y]);
}
ans=max(ans,dp[t.x][t.y]);
}
cout<<ans<<endl;
return 0;
}
by xlxl @ 2019-04-14 19:27:04
志同道合