Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and three different types of guns.
Namely, the two types of monsters are:
a normal monster with hp.
a boss with hp.
And the three types of guns are:
Pistol, deals hp in damage to one monster,
reloading time
Laser gun, deals hp in damage to all the monsters in the current level (including the boss),
reloading time
AWP, instantly kills any monster, reloading time
The guns are initially not loaded, and the Ziota can only reload gun at a time.
The levels of the game can be considered as an array , in which the
-th stage has
normal monsters and
boss. Due to the nature of the game, Ziota cannot use the Pistol (the first type of gun) or AWP (the third type of gun) to shoot the boss before killing all of the
normal monsters.
If Ziota damages the boss but does not kill it immediately, he is forced to move out of the current level to an arbitrary adjacent level (adjacent levels of level are levels
and
, the only adjacent level of level
is level
, the only adjacent level of level
is level
). Ziota can also choose to move to an adjacent level at any time. Each move between adjacent levels are managed by portals with
teleportation time.
In order not to disrupt the space-time continuum within the game, it is strictly forbidden to reload or shoot monsters during teleportation.
Ziota starts the game at level . The objective of the game is rather simple, to kill all the bosses in all the levels. He is curious about the minimum time to finish the game (assuming it takes no time to shoot the monsters with a loaded gun and Ziota has infinite ammo on all the three guns). Please help him find this value.
Input
The first line of the input contains five integers separated by single spaces: — the number of stages,
— the reload time of the three guns respectively,
— the time of moving between adjacent levels.
The second line of the input contains integers separated by single spaces
.
Output
Print one integer, the minimum time to finish the game.
Sample Input
4 1 3 4 3
3 2 5 1
Sample Output
34
Sample Input
4 2 4 4 1
4 5 1 2
Sample Output
31
思路
首先通过观察发现,只可能在最后两层结束。因为如果在其他层结束,不会比在最后两层结束更优。
由于题目条件的规定,我们可以在一层全部打完或者只剩下 的一滴血然后去别的层数打。如果打完了那么就不需要返回,否则处理完别的层后需要返回处理剩下的一滴血。那么可以用
表示前
层已经处理完毕,第
层还剩下
滴血,枚举四种情况进行
的计算就可以得到答案。
注意最后结束的时候不一定在最后一层还可能在倒数第二层,需要额外的计算。
代码
#include <bits/stdc++.h>
using namespace std;
void IO()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
typedef long long ll;
const int maxn = 1e6 + 10;
const ll inf = 0x3f3f3f3f3f3f3f3f;
ll dp[maxn][2];
ll a[maxn];
ll n, r1, r2, r3, d; //r1 = pistol, r2 = laser, r3 = AWP
void solve()
{
cin >> n >> r1 >> r2 >> r3 >> d;
for (int i = 0; i <= n; i++)
dp[i][0] = dp[i][1] = inf;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1][0] = r1 * a[1] + r3;
dp[1][1] = min(r1 * (a[1] + 1), r2);
for (int i = 2; i <= n; i++)
{
dp[i][0] = min({dp[i][0], dp[i - 1][0] + d + r1 * a[i] + r3});
dp[i][0] = min({dp[i][0], dp[i - 1][1] + 3 * d + r1 + min({(a[i] + 2) * r1, r2 + r1, a[i] * r1 + r3})});
dp[i][1] = min({dp[i][1], dp[i - 1][0] + d + min(r1 * (a[i] + 1), r2)});
dp[i][1] = min({dp[i][1], dp[i - 1][1] + 3 * d + min(r1 * (a[i] + 1), r2) + r1});
//printf("debug: dp[%d][0]: %lld, dp[%d][1]: %lld\n", i, dp[i][0], i, dp[i][1]);
}
ll ans = dp[n][0];
ans = min({ans, dp[n - 1][1] + 2 * d + r1 + a[n] * r1 + r3});
cout << ans << '\n';
}
int main()
{
IO();
int _ = 1;
//cin >> _;
while (_--)
solve();
}