using
System;
using
System.Collections.Generic;
class
GFG {
static
Dictionary<Tuple<
int
,
int
>,
int
> m =
new
Dictionary<Tuple<
int
,
int
>,
int
>();
static
int
findMinimum(
int
[] arr,
int
N,
int
pos,
int
turn)
{
Tuple<
int
,
int
> x =
new
Tuple<
int
,
int
>(pos, turn);
if
(m.ContainsKey(x))
{
return
m[x];
}
if
(pos >= N - 1)
{
return
0;
}
if
(turn == 0)
{
int
ans = Math.Min(
findMinimum(arr, N, pos + 1, 1) + arr[pos],
findMinimum(arr, N, pos + 2, 1) + arr[pos] +
arr[pos + 1]);
Tuple<
int
,
int
> v =
new
Tuple<
int
,
int
>(pos, turn);
m[v] = ans;
return
ans;
}
if
(turn != 0)
{
int
ans = Math.Min(
findMinimum(arr, N, pos + 1, 0),
findMinimum(arr, N, pos + 2, 0));
Tuple<
int
,
int
> v =
new
Tuple<
int
,
int
>(pos, turn);
m[v] = ans;
return
ans;
}
return
0;
}
static
int
countPenality(
int
[] arr,
int
N)
{
int
pos = 0;
int
turn = 0;
return
findMinimum(arr, N, pos, turn) + 1;
}
static
void
printAnswer(
int
[] arr,
int
N)
{
int
a = countPenality(arr, N);
int
sum = 0;
for
(
int
i = 0; i < N; i++)
{
sum += arr[i];
}
Console.WriteLine(a);
}
static
void
Main() {
int
[] arr = { 1, 0, 1, 1, 0, 1, 1, 1 };
int
N = 8;
printAnswer(arr, N);
}
}