求助,5个点MLE

P1434 [SHOI2002] 滑雪

@[159号程序员](/user/334586)
by hang09 @ 2022-08-23 20:08:37


@[hang09](/user/547002) ```cpp #include <bits/stdc++.h> using namespace std; int r, c, a[105][105], vis[105][105], ans; int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int dfs(int posx, int posy) { if(vis[posx][posy]) return vis[posx][posy]; vis[posx][posy] = 1; for(int i = 0; i < 4; i++) { int x = dx[i] + posx, y = dy[i] + posy; if(x >= 0 && y >= 0 && x < r && y < c && a[posx][posy] > a[x][y]) { dfs(x, y); vis[posx][posy] = max(vis[posx][posy], vis[x][y] + 1); } } return vis[posx][posy]; } int main() { cin >> r >> c; for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) cin >> a[i][j]; for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) ans = max(ans, dfs(i, j)); cout << ans; return 0; } ```
by 159号程序员 @ 2022-08-23 20:22:13


|