import
java.util.ArrayList;
import
java.util.List;
public
class
FountainActivation {
public
static
boolean
isCovered(List<Integer> activated, List<Integer> fountains) {
int
n = fountains.size();
List<Integer> coverage =
new
ArrayList<>(n);
for
(
int
i =
0
; i < n; i++) {
coverage.add(
0
);
}
for
(
int
i : activated) {
int
left = Math.max(
0
, i - fountains.get(i));
int
right = Math.min(n -
1
, i + fountains.get(i));
for
(
int
j = left; j <= right; j++) {
coverage.set(j,
1
);
}
}
return
coverage.stream().allMatch(val -> val ==
1
);
}
public
static
int
activateFountains(List<Integer> fountains) {
int
n = fountains.size();
int
minFountains = Integer.MAX_VALUE;
for
(
int
i =
1
; i < (
1
<< n); i++) {
List<Integer> activated =
new
ArrayList<>();
for
(
int
j =
0
; j < n; j++) {
if
((i >> j &
1
) ==
1
) {
activated.add(j);
}
}
if
(isCovered(activated, fountains)) {
minFountains = Math.min(minFountains, activated.size());
}
}
return
minFountains;
}
public
static
void
main(String[] args) {
List<Integer> a1 = List.of(
1
,
2
,
1
);
List<Integer> a2 = List.of(
2
,
1
,
1
,
2
,
1
);
System.out.println(activateFountains(a1));
System.out.println(activateFountains(a2));
}
}