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

19317번 - Hanoi 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB744100.000%

문제

Rikka has $n$ disks of distinct sizes on three rods. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack. No disk can be placed on top of a smaller disk.

Given the configuration of disks $S$ and $T,ドル find the number of ways can Rikka transform from $S$ to $T$ in no more than $m$ moves.
As the number of ways can be very large, find it modulo 998ドル,244円,353円$.

Two sequences of moves are different if they have different lengths, or the configurations are different after some moves.

입력

The first line contains two integers $n$ and $m$ (1ドル \leq n \leq 100,ドル 0ドル \leq m \leq 100$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n,ドル the configuration $S$ (1ドル \le a_i \le 3$). These mean that the $i$-th smallest disk is on rod $a_i$.

The third line contains $n$ integers $b_1, b_2, \ldots, b_n,ドル the configuration $T$ given in the same format (1ドル \le b_i \le 3$).

출력

Print one integer: the number of ways modulo 998ドル,244円,353円$.

제한

예제 입력 1

1 2
1
3

예제 출력 1

2

예제 입력 2

2 4
1 1
1 2

예제 출력 2

4

예제 입력 3

1 2
1
1

예제 출력 3

3

예제 입력 4

3 10
1 1 1
2 1 3

예제 출력 4

149

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2018 > Day 7: Ruyi Ji Contest 3 D번

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

출처

대학교 대회

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

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