Submission #549971

#TimeUsernameProblemLanguageResultExecution timeMemory
549971colossal_pepeSkyline (IZhO11_skyline)C++17
0 / 100
2096 ms47964 KiB
#include <iostream> #include <cstring> using namespace std; /* dp[i][carry][carry, pass forward] = min cost for range [i...n] */ const int INF = 1e9; int n, h[301], dp[301][201][201]; int brutus(int i, int c1, int c2) { if (i >= n) return 0; if (dp[i][c1][c2] != -1) return dp[i][c1][c2]; int h_cur = h[i] - c1 - c2; dp[i][c1][c2] = INF; for (int cnt3 = 0; cnt3 <= h_cur; cnt3++) { for (int cnt2 = 0; cnt2 <= h_cur - cnt3; cnt2++) { dp[i][c1][c2] = min(dp[i][c1][c2], brutus(i + 1, c2 + cnt2, cnt3) + 7 * cnt3 + 5 * cnt2 + 3 * (h_cur - cnt3 - cnt2)); } } return dp[i][c1][c2]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(dp, -1, sizeof(dp)); cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; } cout << brutus(0, 0, 0) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...