PLINOVOD | 프로그래밍의 벗 PivotOJ
PivotOJ

PLINOVOD

시간 제한: 1000ms메모리 제한: 256MB출처: CHC 2009 National Competition #1 - JuniorsBOJ 3109
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Mirko owns a bakery on the edge of the city. Because of the financial crisis, Mirko's monthly gas bill for the ovens has become too large so he decided to steal gas from a large pipeline near his bakery. 

The land surrounding the bakery can be modelled by an R×C grid so that the pipeline is in the first column and Mirko's bakery in the last column. 

Mirko will connect pipes to the gas pipeline and his bakery. Some parcels of land are inaccessible and Mirko cannot put pipes through them. 

Every path from the pipeline to the bakery starts in a cell in the first column in the grid, ends in the last column, and each cell on the path is connected to the cell diagonally up-right, right or diagonally down-right. 

In order to pull as much gas from the pipeline as possible, Mirko wants to get as many paths to his bakery as possible. The paths may not cross nor touch. In other words, at most one path may pass through any cell. 

Write a program that calculates the largest number of paths Mirko can pull. 

입력

The first line contains two integers R and C (1 ≤ R ≤ 10000, 5 ≤ C ≤ 500), the dimensions of the grid.Each of the following R lines contains a string of C characters, each being a period '.' or the letter 'x'. The letter 'x' represents an inaccessible parcel of land. The first and last cells in each row will be clear.

출력

Output the largest number of paths Mirko can pull from the pipeline to the bakery. 

 

힌트

[이미지 1]

The grid from the first example, including one possible configuration of paths.

예제

예제 1

입력
5 5
.xx..
..x..
.....
...x.
...x.
출력
2

예제 2

입력
6 10
..x.......
.....x....
.x....x...
...x...xx.
..........
....x.....
출력
5
코드를 제출하려면 로그인하세요.