AcWing 3698. 搬箱子
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 5e2 + 10;
const int M = 1e4 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N];
int me[N][M];
int dfs(int x, int maxi) {
if (me[x][maxi] != -1)return me[x][maxi];
int malen = 0;
for (int i = x + 1 ; i <= n+1; i++) {
if (f[i] > maxi) {
malen = max(malen, 1 + dfs(i, f[i]));
}
}
return me[x][maxi] = malen;
}
void solve() {
memset(me, -1, sizeof(me));
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> f[i];
}
cout << dfs(0, 0);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}