# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
120560 | sofhiasouza | Mountains (IOI17_mountains) | C++14 | 0 ms | 0 KiB |
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>
#include "mountains.h"
using namespace std;
const int maxn = 2010;
int dp[maxn][maxn], n, y[maxn], x[maxn];
long long int cross(int a, int b, int c)
{
return (long long int)(x[b]-x[a])*(y[c]-y[a]) - (y[b]-y[a])*(x[c]-x[a]);
}
int maximun_deevs(vector < int > vet)
{
int n = vet.size();
for(int i = 0 ; i < n ; i++)
{
x[i+1] = i+1;
y[i+1] = vet[i];
}
for(int i = 1 ; i <= n ; i++)
{
dp[i][i] = dp[i-1][i] = 1;
int ult = i-1, res = 0;
for(int j = i-2 ; j > 0 ; j--)
{
if(cross(i, ult, j) >= 0)
{
res += dp[j+1][ult-1];
ult = j;
}
dp[j][i] = max(dp[j][i-1], 1+res+dp[j][ult-1]);
}
}
return dp[1][n];
}