#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int n, v[302], dp[302][202][202];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> v[i];
for (int i = 1; i <= 301; i++)
for (int j = 0; j <= 201; j++)
for (int k = 0; k <= 201; k++)
dp[i][j][k] = INF;
for (int i = 0; i <= v[1]; i++)
dp[2][v[2]][i] = dp[1][i][0] = 3 * (v[1] - i);
for (int i = 2; i <= n; i++) {
for (int j = v[i]; j >= 0; j--)
for (int k = v[i - 1]; k >= 0; k--)
dp[i][j][k] = min(dp[i][j + 1][k] + 3, dp[i][j][k]);
for (int j = v[i]; j >= 0; j--)
for (int k = v[i - 1]; k >= 0; k--)
dp[i][j][k] = min(dp[i][j + 1][k + 1] + 5, dp[i][j][k]);
if (i == n)
continue;
for (int j = min(v[i], min(v[i + 1], v[i - 1])); j >= 0; j--)
for (int k = v[i]; k >= j; k--)
dp[i + 1][v[i + 1] - j][k - j] = min(dp[i + 1][v[i + 1] - j][k - j], dp[i][k][j] + 7 * j);
}
cout << dp[n][0][0];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
48332 KB |
Output is correct |
2 |
Correct |
39 ms |
48324 KB |
Output is correct |
3 |
Correct |
27 ms |
48308 KB |
Output is correct |
4 |
Correct |
28 ms |
48268 KB |
Output is correct |
5 |
Correct |
28 ms |
48304 KB |
Output is correct |
6 |
Correct |
27 ms |
48348 KB |
Output is correct |
7 |
Correct |
27 ms |
48332 KB |
Output is correct |
8 |
Correct |
29 ms |
48272 KB |
Output is correct |
9 |
Correct |
30 ms |
48316 KB |
Output is correct |
10 |
Correct |
30 ms |
48332 KB |
Output is correct |
11 |
Correct |
39 ms |
48324 KB |
Output is correct |
12 |
Correct |
29 ms |
48332 KB |
Output is correct |
13 |
Correct |
35 ms |
48448 KB |
Output is correct |
14 |
Correct |
35 ms |
48260 KB |
Output is correct |
15 |
Correct |
54 ms |
48344 KB |
Output is correct |
16 |
Correct |
51 ms |
48324 KB |
Output is correct |
17 |
Correct |
68 ms |
48332 KB |
Output is correct |
18 |
Correct |
69 ms |
48380 KB |
Output is correct |
19 |
Correct |
60 ms |
48368 KB |
Output is correct |
20 |
Correct |
65 ms |
48372 KB |
Output is correct |