蒟蒻求教为什么MLE

P1434 [SHOI2002] 滑雪

MILLOPE @ 2019-07-13 18:42:22

为什么会MLE啊qwq

#include <bits/stdc++.h> 
using namespace std; 
const int maxn = 110; 

template <class T> 
inline void read(T &s) {
    s = 0; 
    T w = 1, ch = getchar(); 
    while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); }
    while (isdigit(ch)) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
    s *= w;  
}

template <class T> inline T cmax(T x, T y) { return x > y ? x : y; }
template <class T> inline T cmin(T x, T y) { return x < y ? x : y; }

int n, m, ans; 
int a[maxn][maxn], f[maxn][maxn]; 
const int dx[5] = { 1, -1, 0, 0 }; 
const int dy[5] = { 0, 0, -1, 1 }; 

int dfs(int x, int y) {
    if (f[x][y] != 1) return f[x][y]; 
    int cnt = 0; 
    for (int i = 0; i < 4; ++i) {
        int xx = x + dx[i], yy = y + dy[i]; 
        if (xx < 1 || xx > n || yy < 1 || yy > m) continue; 
        if (a[xx][yy] > a[x][y]) continue; 
        cnt = cmax(cnt, dfs(xx, yy) + 1); 
    }
    f[x][y] = cmax(f[x][y], cnt); 
    return f[x][y]; 
}

int main() {
    read(n), read(m); 
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            read(a[i][j]); 
            f[i][j] = 1; 
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            ans = cmax(ans, dfs(i, j)); 
        }
    }

    printf("%d\n", ans);
    return 0; 
}

by MILLOPE @ 2019-07-13 18:42:55

评测记录


by Kendrick_Z @ 2019-07-13 18:47:11

有的时候MLE可能是TLE或者是RE了

经验之谈


by Social_Zhao @ 2019-07-13 18:56:39

dfs爆栈了?(xjb推测)


by 1saunoya @ 2019-07-13 19:09:00

肯定是Dfs的问题


by yu55555 @ 2019-08-28 17:31:15

我和你一样啊,请问解决了吗


|