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;
vector<int>v;
vector<vector<int>>max_table;
long long rec(int indx, vector<int>mx, long long pref){
long long res = 1e18;
if(indx == n + 1)return 0;
for(int i = indx;i <= n;++i){
mx.push_back(max_table[indx][i]);
pref += max_table[indx][i];
res = min(res, (i - indx + 1) * pref + rec(i + 1, mx, pref));
pref -= max_table[indx][i];
mx.pop_back();
}
return res;
}
int main()
{
cin >> n;
v.resize(n + 1);
max_table.assign(n + 1, vector<int>(n + 1));
for(int i = 1;i <= n;++i)cin >> v[i];
for(int i = 1;i <= n;++i){
int mx = -1e9;
for(int j = i;j <= n;++j){
mx = max(mx, v[j]);
max_table[i][j] = mx;
}
}
vector<int>tempo;
cout << rec(1, tempo, 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... |