I_AM_joker @ 2024-02-08 10:54:31
#include <iostream>
using namespace std;
int a[105][105];
int dp[105][105];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int ans=-114514;
int main(){
int n,m;
cin>>n>>m;
for (int i = 1;i<=n;i++){
for (int j = 1;j<=m;j++){
cin>>a[i][j];
dp[i][j]=1;
}
}
for (int i = 1;i<=n;i++){
for (int j = 1;j<=m;j++){
for (int k = 0;k<4;k++){
int nx=i+dx[k],ny=j+dy[k];
if (a[nx][ny]>a[i][j]){
dp[nx][ny]=max(dp[i][j]+1,dp[nx][ny]);
}
}
}
}
for (int i = 1;i<=n;i++){
for (int j = 1;j<=m;j++){
ans=max(dp[i][j],ans);
}
}
cout<<ans<<endl;
return 0;
}
思路是寻找最长距离之后枚举数组
by Chernobog_Belobog @ 2024-02-08 11:10:21
你优先队列呢
by Chernobog_Belobog @ 2024-02-08 11:12:58
这题的dp做法的基础是bfs做法,然后对bfs稍作改变改变
by I_AM_joker @ 2024-02-10 11:29:58
@zhangbomingpp 噢,明白了,谢谢dalao指点!