80分求助
查看原帖
80分求助
464732
luqyou楼主2022/7/25 11:57
#include<iostream>
#include<queue>
using namespace std;
struct Node{
    int i,j,num;
};
struct cmp{
    bool operator()(Node x,Node y){
        return x.num>y.num;
    }
};
Node node;
priority_queue<Node,vector<Node>,cmp>q;
int n,m,maxn,g[101][101],dp[101][101];
int x,y,height;
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j]=1;
            cin>>g[i][j];
            node.i=i;
            node.j=j;
            node.num=g[i][j];
            q.push(node);
        }
    }
    while(!q.empty()){
        
        node=q.top();
        x=node.i;
        y=node.j;
        height=node.num;
        q.pop();
        if(g[x-1][y]<height) 
            dp[x][y]=max(dp[x][y],dp[x-1][y]+1);
        if(g[x+1][y]<height) 
            dp[x][y]=max(dp[x][y],dp[x+1][y]+1);
        if(g[x][y-1]<height) 
            dp[x][y]=max(dp[x][y],dp[x][y-1]+1);
        if(g[x][y+1]<height) 
            dp[x][y]=max(dp[x][y],dp[x][y+1]+1);
        if(maxn<dp[x][y]) 
            maxn=dp[x][y];
    }
    cout<<maxn << endl;
    return 0;
}
2022/7/25 11:57
加载中...