# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
13291 | gs14004 | 스카이라인 (IZhO11_skyline) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]));
}