'commit'
This commit is contained in:
42
TangDou/LanQiaoBei/LanQiao14STEMA202210/TangDou_5.cpp
Normal file
42
TangDou/LanQiaoBei/LanQiao14STEMA202210/TangDou_5.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 110;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
int n, m;
|
||||
int a[N][N];
|
||||
int dx[] = {-1, 0, 1, 0}; //上右下左
|
||||
int dy[] = {0, 1, 0, -1}; //上右下左
|
||||
int res;
|
||||
/*
|
||||
3 3
|
||||
3 2 1
|
||||
3 4 5
|
||||
2 1 3
|
||||
|
||||
答案:
|
||||
4
|
||||
*/
|
||||
void dfs(int x, int y, int last, int cnt) {
|
||||
res = max(res, cnt);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int tx = dx[i] + x, ty = dy[i] + y;
|
||||
if (tx <= 0 || tx > n || ty <= 0 || ty > m) continue;
|
||||
if (a[tx][ty] < last)
|
||||
dfs(tx, ty, a[x][y], cnt + 1);
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
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++)
|
||||
dfs(i, j, INF, 0);
|
||||
|
||||
printf("%d\n", res - 1);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user