Hhy140516 @ 2024-08-28 16:08:09
50pts求调(玄关)
#include<bits/stdc++.h>
using namespace std;
int a[105][105] , n , m , u[105][105] ;
bool f[105][105] ;
int dfs(int x , int y)
{
if( x < 1 || y < 1 || x > n || y > m )
{
return 0 ;
}
if(u[x][y]) return u[x][y] ;
int _1 = 0 , _2 = 0 , _3 = 0 , _4 = 0 ;
if( a[x - 1][y] <= a[x][y] )//上
{
_1 = dfs(x - 1 , y) ;
}
if( a[x + 1][y] <= a[x][y] )//下
{
_2 = dfs(x + 1 , y) ;
}
if( a[x][y - 1] <= a[x][y] )//左
{
_3 = dfs(x , y - 1) ;
}
if( a[x][y + 1] <= a[x][y] )//右
{
_4 = dfs(x , y + 1) ;
}
u[x][y] = max(_1 , max(_2 , max(_3 , _4))) + 1 ;
return u[x][y] ;
}
int main()
{
int maxn = 0 ;
cin >> n >> m ;
for( int i = 1 ; i <= n ; i++ )
{
for( int j = 1 ; j <= m ; j++ ) cin >> a[i][j] ;
}
for( int i = 1 ; i <= n ; i++ )
{
for( int j = 1 ; j <= m ; j++ )
{
int r = dfs(i , j) ;
maxn = max(maxn , r) ;
//cout << r << " " ;
}
//cout << "\n" ;
}
cout << maxn ;
return 0 ;
}
by firefly13163 @ 2024-08-28 16:34:11
#include<iostream>
#include<algorithm>
using namespace std;
int a[105][105] , n , m , u[105][105] ;
bool f[105][105] ;
int dfs(int x , int y)
{
if( x < 1 || y < 1 || x > n || y > m )
{
return 0 ;
}
if(u[x][y]) return u[x][y] ;
u[x][y]=1;
int _1 = 0 , _2 = 0 , _3 = 0 , _4 = 0 ;
if( a[x - 1][y] < a[x][y]&&x-1>0 )
{
if(u[x-1][y])
{
_1=u[x-1][y];
}
else
_1 = dfs(x - 1 , y) ;
}
if( a[x + 1][y] < a[x][y]&&x+1<=n )
{
if(u[x+1][y])
{
_2=u[x+1][y];
}
else
_2 = dfs(x + 1 , y) ;
}
if( a[x][y - 1] < a[x][y]&&y-1>0 )
{
if(u[x][y-1])
{
_3=u[x][y-1];
}
else
_3 = dfs(x , y - 1) ;
}
if( a[x][y + 1] < a[x][y]&&y+1<=m )
{
if(u[x][y+1])
{
_4=u[x][y+1];
}
else
_4 = dfs(x , y + 1) ;
}
u[x][y] =max(u[x][y], max(_1 , max(_2 , max(_3 , _4)))+1 );
return u[x][y] ;
}
int main()
{
int maxn = 0 ;
cin >> n >> m ;
for( int i = 1 ; i <= n ; i++ )
{
for( int j = 1 ; j <= m ; j++ ) cin >> a[i][j] ;
}
for( int i = 1 ; i <=n ; i++ )
{
for( int j = 1 ; j <=m ; j++ )
{
int r = dfs(i , j) ;
maxn = max(maxn , r) ;
//cout << r << " " ;
}
//cout << "\n" ;
}
cout << maxn ;
return 0 ;
}
刚刚忘选类型了,重发一下
by Hhy140516 @ 2024-08-30 12:19:03
谢谢巨佬,以