Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- int n, v;
- cin >> n;
- vector<vector<int>> dp(n / 2 + 1, vector<int>(2));
- for (int i = 1; i <= n / 2; i++) {
- dp[i][0] = 1e9;
- dp[i][1] = 1e9;
- }
- for (int i = 0; i < n; i++) {
- cin >> v;
- for (int j = n / 2; j >= 0; j--) {
- if (v == 0 || v % 2 > 0) {
- dp[j][1] = min(dp[j][1], dp[j][0] + 1);
- } else {
- dp[j][1] = 1e9;
- }
- if (j > 0 && v % 2 == 0) {
- dp[j][0] = min(dp[j - 1][0], dp[j - 1][1] + 1);
- } else {
- dp[j][0] = 1e9;
- }
- }
- }
- cout << min(dp[n / 2][0], dp[n / 2][1]) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment