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 <vector>
#include "mountains.h"
using namespace std;
#define ll long long
const int N = 2005;
struct Mountain{
ll x, y;
} v[N];
int dp[N][N];
long long infas(int a, int b, int c)
{
return (v[b].x - v[a].x) * (v[c].y - v[a].y) >= (v[b].y - v[a].y) * (v[c].x - v[a].x);
}
int maximum_deevs(vector<int> h)
{
int n = h.size(), i, j;
for (i = 1; i <= n; i++)
{
v[i].x = i - 1;
v[i].y = h[i - 1];
}
for (i = 1; i <= n; i++)
{
dp[i][i] = dp[i - 1][i] = 1;
int lstseen = i - 1, cnt = 0;
for (j = i - 2; 1 <= j; j--)
{
if (infas(j, lstseen, i))
{
cnt += dp[j + 1][lstseen - 1];
lstseen = j;
}
dp[j][i] = max(dp[j][i - 1], 1 + cnt + dp[j][lstseen - 1]);
}
}
return dp[1][n];
}/*
int main()
{
int n;
cin >> n;
vector <int> h(n);
for (int i = 0; i < n; i++)
cin >> h[i];
cout << maximum_deevs(h);
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... |