Flag performance

시간 제한2초메모리 제한1024 MB

요약
T개의 초기 깃발 순열마다 정확히 K번의 교환으로 모든 팀원이 자기 색 깃발을 들게 되는 교환 순서의 수를 1e9+7로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 조합론, 수학, 비트 연산
정답자
아직 제출이 없습니다

문제

You are in charge of a team of sorted gymnastics. This new discipline involves teams of NN members. Each team member dresses with a different colour (a number from 11 to NN) and holds a coloured flag. Flags have unique colours, also numbered from 11 to NN. A performance consists of exactly KK 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 TT 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 TT 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,0071\\, 000\\, 000\\, 007.

입력

Each line consists of space-separated integers. The first input line contains the numbers NN, KK, and TT. Then follow TT lines. The kkth such line consists of NN distinct space-separated integers c_k,1,c_k,2,…,c_k,Nc\_{k,1}, c\_{k,2}, \dots , c\_{k,N}, representing the kkth initial configuration of flags among team members. Here, c_k,ic\_{k,i} is colour number of the flag initially in the hands of the team member whose outfit colour is ii.

출력

The output should contain TT lines. The kkth such line should consist of a single number: the number of possible sequences of exchanges that start from the kkth configuration and satisfy the constraints listed above, modulo 1,000,000,0071\\, 000\\, 000\\, 007.

제한

  • 2≤N≤302 \le N \le 30
  • 1≤K≤501 \le K \le 50
  • 1≤T≤10,0001 \le T \le 10\\, 000

예제3

  1. 예제 1

    입력
    4 2 1
    4 1 2 3
    
    예상 출력
    0
    
  2. 예제 2

    입력
    4 3 1
    4 1 2 3
    
    예상 출력
    16
    
  3. 예제 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
    
    예상 출력
    310571736
    0
    745108126
    996135367
    597596468
    745108126
    0
    0
    310571736
    0