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 "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 405;
int a[N];
int n, d;
int dp[N][N][N];
int bt (int id, int mx, int la) {
if (id == n) return 0;
int& ret = dp[id][mx][la];
if (ret != -1) {
return ret;
}
if (id - la > d && mx != 0) return 0;
ret = max(bt(id + 1, mx, la), bt(id + 1, max(mx, a[id]), id) + (int) (a[id] > mx));
return ret;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> d;
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
}
memset(dp, -1, sizeof dp);
cout << bt(0, 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... |