Submission #448284

#TimeUsernameProblemLanguageResultExecution timeMemory
448284stefantagaSkyline (IZhO11_skyline)C++14
100 / 100
73 ms50464 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 5; const int N = 305; const int H = 205; int dp[N][H][H]; ///dp[i][j][k] = sunt la cladirea i iar pe i mai am j iar pe i-1 mai am k int h[N]; int main() { int n, i, j, k; cin >> n; for (i = 1; i <= n; i++) cin >> h[i]; memset(dp, INF, sizeof dp); for (i = 0; i <= h[1]; i++) dp[2][h[2]][i] = dp[1][i][0] = 3 * (h[1] - i); for (i = 2; i <= n; i++) { for (j = h[i]; 0 <= j; j--) for (k = h[i - 1]; 0 <= k; k--) dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k] + 3); for (j = h[i]; 0 <= j; j--) for (k = h[i - 1]; 0 <= k; k--) dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k + 1] + 5); for (int l = min(h[i + 1], min(h[i], h[i - 1])); 0 <= l; l--) ///atateam am scos din v[i - 1] ca tb sa l fac 0 for (j = h[i]; l <= j; j--) dp[i + 1][h[i + 1] - l][j - l] = min(dp[i][j][l] + 7 * l, dp[i + 1][h[i + 1] - l][j - l]); } cout << dp[n][0][0]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...