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

31485번 - Flag performance 다국어

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

문제

You are in charge of a team of sorted gymnastics. This new discipline involves teams of $N$ members. Each team member dresses with a different colour (a number from 1ドル$ to $N$) and holds a coloured flag. Flags have unique colours, also numbered from 1ドル$ to $N$. A performance consists of exactly $K$ steps. At each step, two members exchange their flags. You are free to choose the initial configuration of the flags. The only constraint is that, at the end of the performance, each participant must hold the flag corresponding to the colour of his outfit.

Being the team captain, you would like the performance to be as unpredictable as possible. You consider $T$ possible initial configurations of flags among the team members, and wonder: in how many ways can the team perform the task for each of these initial configurations?

For each of the given $T$ initial configurations, compute the number of possible ways to do the performance. As the answers may be very large, return them modulo the prime number 1ドル,円 000,円 000,円 007$.

입력

Each line consists of space-separated integers. The first input line contains the numbers $N,ドル $K,ドル and $T$. Then follow $T$ lines. The $k$th such line consists of $N$ distinct space-separated integers $c_{k,1}, c_{k,2}, \dots , c_{k,N},ドル representing the $k$th initial configuration of flags among team members. Here, $c_{k,i}$ is colour number of the flag initially in the hands of the team member whose outfit colour is $i$.

출력

The output should contain $T$ lines. The $k$th such line should consist of a single number: the number of possible sequences of exchanges that start from the $k$th configuration and satisfy the constraints listed above, modulo 1ドル,円 000,円 000,円 007$.

제한

  • 2ドル \le N \le 30$
  • 1ドル \le K \le 50$
  • 1ドル \le T \le 10,円 000$

예제 입력 1

4 2 1
4 1 2 3

예제 출력 1

0

It is impossible to sort the flags with two exchanges.

예제 입력 2

4 3 1
4 1 2 3

예제 출력 2

16

예제 입력 3

6 15 10
5 6 1 2 4 3
2 4 1 6 5 3
4 1 3 6 5 2
1 3 2 4 5 6
4 5 6 1 2 3
1 2 5 3 6 4
6 4 2 3 1 5
3 6 4 1 2 5
4 5 1 2 6 3
6 1 4 3 2 5

예제 출력 3

310571736
0
745108126
996135367
597596468
745108126
0
0
310571736
0

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2023-2024 D번

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

출처

대학교 대회

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

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