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;
int N, D;
vector<int> arr;
vector<vector<int>> dp = vector<vector<int>>(8000, vector<int>(8000, -1));
int rec(int n, int cmax = -1)
{
int score = arr[n] > cmax ? 1 : 0;
int tmp = 0;
int cmal = cmax;
if (dp[n][cmax] != -1)
return dp[n][cmax];
if (n == N - 1)
return dp[n][cmax] = score;
cmax = max(cmax, arr[n]);
for (int i = 1; i <= D && i + n <= N - 1; i++)
tmp = max(tmp, rec(n + i, cmax));
return dp[n][cmal] = score + tmp;
}
int main()
{
cin >> N >> D;
arr.resize(N);
for (int &i : arr)
cin >> i;
assert(N <= 400);
//compression
{
vector<int> arr2 = arr;
sort(arr2.begin(), arr2.end());
map<int, int> copr;
int c = 1;
copr[arr2[0]] = ++c;
for (int i = 1; i < N; i++)
if (arr2[i - 1] < arr2[i])
copr[arr2[i]] = ++c;
for (int &i : arr)
i = copr[i];
}
int score = 0;
for (int i = 0; i < N; i++)
score = max(score, rec(i));
cout << score;
}
# | 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... |