The Water Bowls
면접 대비시간 제한1초메모리 제한1024 MB
상태가 0 또는 1인 물그릇 20개가 일렬로 놓여 있고, 한 그릇을 뒤집으면 양옆도 함께 뒤집힌다. 모두 0으로 만드는 최소 뒤집기 횟수를 구한다.
문제
The cows have a line of 20 water bowls from which they drink. The bowls can be either right-side-up (properly oriented to serve refreshing cool water) or upside-down (a position which holds no water). They want all 20 water bowls to be right-side-up and thus use their wide snouts to flip bowls.
Their snouts, though, are so wide that they flip not only one bowl but also the bowls on either side of that bowl (a total of three or -- in the case of either end bowl -- two bowls).
Given the initial state of the bowls (1=undrinkable, 0=drinkable -- it even looks like a bowl), what is the minimum number of bowl flips necessary to turn all the bowls right-side-up?
입력
- Line 1: A single line with 20 space-separated integers
출력
- Line 1: The minimum number of bowl flips necessary to flip all the bowls right-side-up (i.e., to 0). For the inputs given, it will always be possible to find some combination of flips that will manipulate the bowls to 20 0's.