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

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

Walking Home

면접 대비

시간 제한2초메모리 제한1024 MB

요약
N x N 격자에서 왼쪽 위에서 오른쪽 아래로 아래나 오른쪽으로만 이동하되 방향 전환이 최대 K번이고 건초더미 칸은 지날 수 없을 때 서로 다른 경로의 수를 구한다.
난이도

보통10점 중 5점

유형
동적 계획법, 배열
정답자
아직 제출이 없습니다

문제

Bessie the cow is trying to walk from her favorite pasture back to her barn.

The pasture and farm are on an N×NN \times N grid (2≤N≤502 \leq N \leq 50), with her pasture in the top-left corner and the barn in the bottom-right corner. Bessie wants to get home as soon as possible, so she will only walk down and to the right. There are haybales in some locations that Bessie cannot walk through; she must walk around them.

Bessie is feeling a little tired today, so she wants to change the direction she walks at most KK times (1≤K≤31 \leq K \leq 3) .

How many distinct paths can Bessie walk from her favorite pasture to the barn? Two paths are distinct if Bessie walks in a square in one path but not in the other.

입력

The input for each test case contains TT sub-test cases, each describing a different farm and each of which must be answered correctly to pass the full test case. The first line of input contains TT (1≤T≤501 \leq T \leq 50). Each of the TT sub-test cases follow.

Each sub-test case starts with a line containing NN and KK.

The next NN lines each contain a string of NN characters. Each character is either . if it is empty or H if it has a haybale. It is guaranteed the top-left and bottom-right corners of the farm will not contain haybales.

출력

Output TT lines, the iith line containing the number of distinct paths Bessie can take in the iith sub-test case.

예제1

  1. 예제 1

    입력
    7
    3 1
    ...
    ...
    ...
    3 2
    ...
    ...
    ...
    3 3
    ...
    ...
    ...
    3 3
    ...
    .H.
    ...
    3 2
    .HH
    HHH
    HH.
    3 3
    .H.
    H..
    ...
    4 3
    ...H
    .H..
    ....
    H...
    
    예상 출력
    2
    4
    6
    2
    0
    0
    6