Logo
(追記) (追記ここまで)

23880번 - Walking Home 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB47432326270.811%

문제

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

The pasture and farm are on an $N \times N$ grid (2ドル \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 $K$ times (1ドル \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 $T$ 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 $T$ (1ドル \leq T \leq 50$). Each of the $T$ sub-test cases follow.

Each sub-test case starts with a line containing $N$ and $K$.

The next $N$ lines each contain a string of $N$ 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 $T$ lines, the $i$th line containing the number of distinct paths Bessie can take in the $i$th sub-test case.

제한

예제 입력 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...

예제 출력 1

2
4
6
2
0
0
6

We'll denote Bessie's possible paths as strings of D's and R's, indicating that Bessie moved either down or right, respectively.

In the first sub-test case, Bessie's two possible walks are DDRR and RRDD.

In the second sub-test case, Bessie's four possible walks are DDRR, DRRD, RDDR, and RRDD.

In the third sub-test case, Bessie's six possible walks are DDRR, DRDR, DRRD, RDDR, RDRD, and RRDD.

In the fourth sub-test case, Bessie's two possible walks are DDRR and RRDD.

In the fifth and sixth sub-test cases, it is impossible for Bessie to walk back to the barn.

In the seventh sub-test case, Bessie's six possible walks are DDRDRR, DDRRDR, DDRRRD, RRDDDR, RRDDRD, and RRDRDD.

힌트

출처

Olympiad > USA Computing Olympiad > 2021-2022 Season > USACO 2021 December Contest > Bronze 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /