60pts 求条
查看原帖
60pts 求条
728840
covonant楼主2024/10/15 13:57
#include<bits/stdc++.h>
using namespace std;
int a[105][105];
int dp[105][105];//从这个点出发的最长路径 
struct node{
	int x,y,h;
}sx[10005];
int r,c;
int pos;
bool cmp(node a,node b){
	return a.h<b.h;
}
int main(){
	cin>>r>>c;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			cin>>a[i][j];
			pos++;
			sx[pos]={i,j,a[i][j]};
		}
	}
	sort(sx+1,sx+pos+1,cmp);
	for(int i=1;i<=pos;i++){
		int x=sx[i].x;
		int y=sx[i].y;
		int h=sx[i].h;
		if(x>1) dp[x][y]=max(dp[x][y],dp[x-1][y]);
		if(y>1) dp[x][y]=max(dp[x][y],dp[x][y-1]);
		if(x<r) dp[x][y]=max(dp[x][y],dp[x+1][y]);
		if(y<c) dp[x][y]=max(dp[x][y],dp[x][y+1]);
		dp[x][y]++;
	}
	int ans=0;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			ans=max(ans,dp[i][j]);
		}
	}
	cout<<ans;
	return 0;
}
2024/10/15 13:57
加载中...