-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1287C.cpp
More file actions
65 lines (61 loc) · 1.32 KB
/
1287C.cpp
File metadata and controls
65 lines (61 loc) · 1.32 KB
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
56
57
58
59
60
61
62
63
64
65
//21171_somesh || asomesh999
//AC
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;
int n;
vi arr;
ll dp[110][110][110][3];
ll recurse(int pos, int prev, int even, int odd) {
if (pos >= n) {
return 0;
}
ll &ans = dp[pos][even][odd][prev];
if (ans != -1) return ans;
ans = INT_MAX;
if (arr[pos] == 0) {
if (odd) {
int add = (prev == 1) ? 1 : 0;
ans = min(ans, recurse(pos + 1, 2, even, odd - 1) + add);
}
if (even) {
int add = (prev == 2) ? 1 : 0;
ans = min(ans, recurse(pos + 1, 1, even - 1, odd) + add);
}
} else {
int add = 0;
if (prev == 1) {
add = (arr[pos] % 2 == 0) ? 0 : 1;
} else if (prev == 2) {
add = (arr[pos] % 2) ? 0 : 1;
}
ans = min(ans, recurse(pos + 1, (arr[pos] % 2) + 1, even, odd) + add);
}
return ans;
}
int main()
{
io
cin >> n;
arr.resize(n);
int even = 0, odd = 0;
fr(i, 0, n) {
cin >> arr[i];
if (arr[i] == 0) continue;
if (arr[i] % 2 == 0) even++;
else odd++;
}
even = n / 2 - even;
odd = (n + 1) / 2 - odd;
memset(dp, -1, sizeof dp);
cout << recurse(0, 0, even, odd);
return 0;
}