-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1418C.cpp
More file actions
55 lines (44 loc) · 796 Bytes
/
CF_1418C.cpp
File metadata and controls
55 lines (44 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int FR_TURN = 0;
const int MY_TURN = 1;
int n;
int a[200000];
int dp[2][200001];
int solve(int turn, int boss) {
if (boss >= n)
{
return 0;
}
if (dp[turn][boss] != -1)
{
return dp[turn][boss];
}
int ret = 987654321;
if (turn == FR_TURN)
{
ret = min(ret, solve(1 - turn, boss + 1) + a[boss]);
ret = min(ret, solve(1 - turn, boss + 2) + a[boss] + a[boss + 1]);
}
else
{
ret = min(ret, solve(1 - turn, boss + 1));
ret = min(ret, solve(1 - turn, boss + 2));
}
return dp[turn][boss] = ret;
}
int main() {
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
memset(dp, -1, sizeof(dp));
cout << solve(FR_TURN, 0) << endl;
}
}