This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstring>
using namespace std;
const int N = 405;
int n, d, a[N], dp[N][N][N];
bool vis[N][N][N];
int brutus(int i, int j, int k) {
if (i > n) return (j == n ? 0 : -1000);
if (vis[i][j][k]) return dp[i][j][k];
vis[i][j][k] = 1;
if (j != 0 and i - j > d) dp[i][j][k] = -1000;
else dp[i][j][k] = max(brutus(i + 1, j, k), (a[i] > a[k]) + brutus(i + 1, i, (a[i] > a[k] ? i : k)));
return dp[i][j][k];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> d;
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
// if (n > 400) cout << "parbona" << '\n';
memset(vis, 0, sizeof(vis));
cout << brutus(1, 0, 0) << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |