New_hope @ 2022-08-18 22:12:21
#include<bits/stdc++.h>
#define l 105
using namespace std;
int s[l][l],dp[l][l];
int search(int a,int b){
if(s[a-1][b]>s[a][b]){
dp[a-1][b]=max(dp[a-1][b],dp[a][b]+1);
search(a-1,b);
}
if(s[a][b-1]>s[a][b]){
dp[a][b-1]=max(dp[a][b-1],dp[a][b]+1);
search(a,b-1);
}
if(s[a][b+1]>s[a][b]){
dp[a][b+1]=max(dp[a][b+1],dp[a][b]+1);
search(a,b+1);
}
if(s[a+1][b]>s[a][b]){
dp[a+1][b]=max(dp[a+1][b],dp[a][b]+1);
search(a+1,b);
}
return dp[a][b];
}
int main(){
int r,c;
int minn=200000000,ans=0,sx,sy;
int i,j;
cin>>r>>c;
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
cin>>s[i][j];
if(s[i][j]<minn){
minn=s[i][j];
sx=i;
sy=j;
}
}
}
dp[sx][sy]=1;
// cout<<sx<<" "<<sy<<endl;
search(sx,sy);
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
// cout<<dp[i][j]<<" ";
if(dp[i][j]>ans){
ans=dp[i][j];
}
}
// cout<<endl;
}
cout<<ans;
return 0;
}
我心态崩了,俩错一超时
by Feng_Jing @ 2022-08-18 22:15:49
谁把那个求助计费表搬上来,我忘记要收多少了(doge
by JackMerryYoung @ 2022-08-18 22:19:40
FengJingFJ2022 Sus... Crew Vote and Reject.
by LuoDiary @ 2022-08-18 22:25:30
有没有一种可能
数据是:
2 3
1 2 3
3 4 0
时会出错
by LuoDiary @ 2022-08-18 22:40:19
可以试试
#include<bits/stdc++.h>
#define l 105
using namespace std;
int s[l][l],dp[l][l];
int search(int a,int b){
if(s[a-1][b]>s[a][b]&&dp[a-1][b]<dp[a][b]+1){
dp[a-1][b]=dp[a][b]+1;
search(a-1,b);
}
if(s[a][b-1]>s[a][b]&&dp[a][b-1]<dp[a][b]+1){
dp[a][b-1]=dp[a][b]+1;
search(a,b-1);
}
if(s[a][b+1]>s[a][b]&&dp[a][b+1]<dp[a][b]+1){
dp[a][b+1]=dp[a][b]+1;
search(a,b+1);
}
if(s[a+1][b]>s[a][b]&&dp[a+1][b]<dp[a][b]+1){
dp[a+1][b]=dp[a][b]+1;
search(a+1,b);
}
return dp[a][b];
}
int main(){
int r,c;
int minn=200000000,ans=0,sx,sy;
int i,j;
cin>>r>>c;
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
cin>>s[i][j];
dp[i][j]=1;
//if(s[i][j]<minn){
// minn=s[i][j];
// sx=i;
// sy=j;
// }
}
}
for(i=1;i<=r;i++)
for(j=1;j<=c;j++)
search(i,j);
// dp[sx][sy]=1;
// cout<<sx<<" "<<sy<<endl;
// search(sx,sy);
for(i=1;i<=r;i++){
for(j=1;j<=c;j++){
// cout<<dp[i][j]<<" ";
if(dp[i][j]>ans){
ans=dp[i][j];
}
}
// cout<<endl;
}
cout<<ans;
return 0;
}
by New_hope @ 2022-08-19 08:28:46
@lty3194 牛批啊我焯
感谢大佬!!
by LuoDiary @ 2022-08-20 22:56:30
@New_hope
我是蒟蒻啊~QAQ
有问题可以一起讨论的