loegoo @ 2024-12-07 22:03:00
#include<bits/stdc++.h>
using namespace std;
int r,c,ans;
int dp[101][101],h[101][101];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
struct ss{
int x,y,n;
}a[1000010];
bool cmp(ss t1,ss t2){
return t1.n<t2.n;
}
int main(){
cin>>r>>c;
int k=1;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
dp[i][j]=1;
a[k].x=i;
a[k].y=j;
cin>>a[k].n;
h[i][j]=a[k].n;
k++;
}
}
int x,y,x1,y1;
sort(a+1,a+1+r*c,cmp);//从小到大dp
for(int i=1;i<=r*c;i++){
x=a[i].x;
y=a[i].y;
for(int k=0;k<=3;k++){
x1=x+dx[k];
y1=y+dy[k];
if(h[x1][y1]<h[x][y]&&x1>0&&x1<=r&&y1>0&&y1<=c){//边界判断+高度判断
dp[x][y]=max(dp[x][y],dp[x1][y1]+1);
if(dp[x][y]>ans)//更新答案
ans=dp[x][y];
}
}
}
cout<<ans;
return 0;
}
by huangruize3 @ 2024-12-14 21:09:55
@loegoo
你的ans计数器要从1开始,不能从0开始
把int r,c,ans;
变为int r,c,ans=1;
就可AC;
by huangruize3 @ 2024-12-14 21:11:19
@loegoo 求关!!!!!!!!!!!!
by loegoo @ 2024-12-14 21:52:05
@huangruize3 AC力,谢谢!