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 "mountains.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cstdio>
#include <utility>
#include <queue>
#include <math.h>
#include <set>
#include <bitset>
#include <cmath>
#include <bitset>
#include <stack>
#include <cstring>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 2010;
int dp[MAXN][MAXN];
int maximum_deevs(vector<int> y) {
int n = y.size();
dp[0][0] = 1;
int prev = -1;
double curr = -1e9;
for(int i = 1; i < n; i++) {
for(int j = i; j >= 0; j--) {
if(i == j) {
curr = -1e9;
dp[j][i] = 1;
prev = i;
continue;
}
dp[j][i] = dp[j][i - 1];
double slope = (double)(y[j] - y[i])/(double)(i - j);
if(slope >= curr) {
dp[j][i] = max(dp[j][i], dp[j + 1][i]);
curr = slope;
prev = j;
}
else dp[j][i] = max(dp[j][i], dp[j][prev - 1] + dp[prev + 1][i]);
}
}
return dp[0][n - 1];
}
# | 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... |