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

Spaceship

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie the cow has been abducted by aliens and is now trapped inside an alien
spaceship! The spaceship has \(N\) \((1\le N\le 60)\) rooms labeled \(1\ldots N\), with
one-way doors connecting between some pairs of rooms (due to the strange alien
technology at play, it is even possible for a door to lead from a room back to
itself!). However, no two doors share the same starting and end room.
Additionally, Bessie has a remote with buttons numbered \(1\ldots K\)
\((1 \le K \le 60)\).

The aliens will release Bessie if she can complete a strange task. First, they
will choose two rooms, \(s\) and \(t\) \((1 \le s, t \le N)\), and two numbers, \(b_s\)
and \(b_t\) \((1 \le b_s, b_t \le K)\). They will start Bessie in room \(s\) and
immediately have her press button \(b_s\). Bessie will then proceed to navigate
the ship while pressing buttons. There are a few rules for what Bessie can do:

  • In each room, after pressing exactly one button, she must choose to either exit through a door to another (possibly the same) room or stop.
  • Once Bessie presses a button, it is invalid for her to press the same button again unless, in the time between uses, she has pressed a button with a higher number. In other words, pressing button number \(x\) will make it unavailable for use, while all buttons with numbers \( will be reset and again available for use.
  • If Bessie presses an invalid button, she automatically fails and the aliens will keep her.

Bessie is released only if she stops in room \(t\), the last button she pressed
was \(b_t\), and no invalid buttons were ever pressed.

Bessie is worried that she may not be able to complete the task. For \(Q\)
\((1\le Q\le 60)\) queries, each consisting of what Bessie considers a likely
choice of \(s, t, b_s\), and \(b_t\), Bessie wants to know the number of sequences
of rooms and button presses that would lead to her release. Report your answers
modulo \(10^9 + 7\) as they may be very large.

Problem credits: Benjamin Qi

제약

SCORING

  • In test cases 4-7, \(K\le 5\) and \((b_s,s)\) is the same for all queries.
  • In test cases 8-11, \(b_s=K-1\) and \(b_t=K\) for each query.
  • In test cases 12-15, \(N,K,Q\le 20\).
  • In test cases 16-23, there are no additional constraints.

Problem credits: Benjamin Qi

입력 형식

The first line contains \(N,K,Q\).

The next \(N\) lines each contain \(N\) bits (each 0 or 1). The \(j\)-th entry of the
\(i\)-th line is 1 if there exists a door from room \(i\) to room \(j\), and 0 if no
such door exists.

This is followed by \(Q\) lines, each containing four integers \(b_s\), \(s\), \(b_t\),
\(t\), denoting the starting button, starting room, final button, and final room
respectively.

출력 형식

The number of sequences for each of the \(Q\) queries modulo \(10^9+7\) on separate
lines.

예제 1
입력
6 3 8
010000
001000
000100
000010
000000
000001
1 1 1 1
3 3 1 1
1 1 3 3
1 1 1 5
2 1 1 5
1 1 2 5
3 1 3 5
2 6 2 6
출력
1
0
1
3
2
2
0
5
설명

The doors connect rooms \(1\to 2\), \(2 \to 3\), \(3\to 4\), \(4\to 5\), and \(6\to 6\).

For the first query, Bessie must stop immediately after pressing the first
button.

For the second query, the answer is clearly zero because there is no way to get
to room 1 from room 3.

For the third query, Bessie's only option is to move from room 1 to room 2 to
room 3 while pressing buttons 1, 2, and 3.

For the fourth query, Bessie's pattern of movement is fixed, and she has three
possible sequences of button presses:

  • \((1,2,3,2,1)\)
  • \((1,2,1,3,1)\)
  • \((1,3,1,2,1)\)

For the last query, Bessie has five possible sequences of button presses:

  • \((2)\)
  • \((2,3,2)\)
  • \((2,3,1,2)\)
  • \((2,1,3,2)\)
  • \((2,1,3,1,2)\)
예제 2
입력
6 4 6
001100
001110
101101
010111
110111
000111
3 2 4 3
3 1 4 4
3 4 4 1
3 3 4 3
3 6 4 3
3 1 4 2
출력
26
49
29
27
18
22
설명

This test case satisfies the constraints for all subtasks aside from the first.

예제 3
입력
6 10 5
110101
011001
001111
101111
111010
000001
2 5 2 5
6 1 5 2
3 4 8 3
9 3 3 5
5 1 3 4
출력
713313311
716721076
782223918
335511486
539247783
설명

Make sure to output the answers modulo \(10^9+7\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2020-2021 > December > Platinum

태그

평가 및 의견

Spaceship

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Spaceship

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