아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Painting

시간 제한8초메모리 제한512 MB

요약
삼각형 모양으로 배열된 흰 원과 검은 원에서, 검은 원을 지나지 않으면서 세 변 중 하나에 평행한 직선들로 모든 흰 원을 덮는 최소 횟수를 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 비트 연산, 완전 탐색, 조합론
정답자
아직 제출이 없습니다

문제

You have figures that consist of white circles (◦) and black circles (•) locating in the shape of the regular triangle. An example of such figures is as follows.

Figure 4: An example triangle

Now let us consider painting all the white circles into red. You can paint white circles in one step, if the white circles are on a line in parallel to one of the edges of the triangle. In order words, you can paint either from left to right, from upper-right to lower-left, or upper-right to lower-left.

Figure 5: Three kinds of steps

You can paint white circles more than once, but you must not paint any black circles (i.e. the line must not meet the black circles).

The problem is that how many steps do you need to paint all the white circles in the given figures. In the case of the example above we need six steps to paint all the white circles, where one of such painting is as follows.

Figure 6: An example way to paint all circles in 6 steps

입력

Input consists of multiple test cases.

The first line of each case contains a single positive integer N (N ≤ 15) that specifies the size of triangles. The following N lines represent a figure; the i-th line contains i characters of either w or b, where w denotes a white circle and b denotes a black circle.

Input is terminated by a line that contains a single zero, which should not be processed.

출력

For each case, your program should print the minimum number of steps to paint all the white circles in one line.

예제1

  1. 예제 1

    입력
    6
    w
    ww
    bww
    wwwb
    wwwww
    wwbwww
    0
    
    예상 출력
    6