# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13291 | gs14004 | Skyline (IZhO11_skyline) | 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 <cstdio>
#include <algorithm>
using namespace std;
int a[305],n;
int dp[305][205][205];
int f(int pos, int p1, int p2){
if(pos == n) return 0;
int p3 = a[pos+2];
int ret = f(pos+1,p2,p3) + 3 * p1;
if(pos + 1 < n){
int cut = min(p1,p2);
ret = min(ret,f(pos+1,p2-cut,p3) + 5 * cut, 3 * (p1 - cut));
}
if(pos + 2 < n){
int cut = min(p1,min(p2,p3));
ret = min(ret,f(pos+1,p2-cut,p3-cut) + 7 * cut + 3 * (p1 - cut));
}
return dp[pos][p1][p2] = ret;
}
int main(){
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d",&a[i]);
}
printf("%d",f(0,a[0],a[1]));
}