RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0485

Walking Home

Gold IV 골드 IV
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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.

Problem credits: Nick Wu

제약

SCORING

  • Test case 2 satisfies \(K = 1\).
  • Test cases 3-5 satisfy \(K = 2\).
  • Test cases 6-10 satisfy \(K = 3\).

Problem credits: Nick Wu

입력 형식

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 \(\texttt{.}\) if it is empty or \(\texttt{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...
출력
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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2021-2022 > December > Bronze

태그

평가 및 의견

Walking Home

개요
출제자 난이도 Gold IV 골드 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Walking Home

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8