#P11028. [COTS 2020] 龙猫 Totoro

    ID: 12441 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>2020O2优化群论置换COCI(克罗地亚)

[COTS 2020] 龙猫 Totoro

Background

Translated from Izborne Pripreme 2020 (Croatian IOI/CEOI Team Selection) D2T3。1s,0.5G\texttt{1s,0.5G}。

Problem Description

You are given KK permutations π1,π2,⋯ ,πK\pi_1,\pi_2,\cdots,\pi_K of 1∼N1 \sim N。

Find the expected number of inversions of a permutation in the permutation group G(S,∘)G(S,\circ), where the binary operation ∘\circ is permutation composition, and for all 1≤i≤K1 \le i \le K, we have πi∈S\pi_i \in S。

More specifically, we define (π∘τ)(i)=π(τ(i))(\pi \circ \tau)(i) = \pi(\tau(i))。

The group G(S,∘)G(S,\circ) is an algebraic structure satisfying the following properties:

  • Closure: for all a,b∈Sa,b \in S, we have a∘b∈Sa \circ b \in S;
  • Associativity: for all a,b,c∈Sa,b,c \in S, we have (a∘b)∘c=a∘(b∘c)(a \circ b) \circ c = a \circ (b \circ c);
  • Identity element: there exists e∈Se \in S such that for all a∈Sa \in S, a∘e=e∘a=aa \circ e = e \circ a = a;
  • Inverse element: for all a∈Sa \in S, there exists b∈Sb \in S such that a∘b=b∘a=ea \circ b = b \circ a = e。

Define L(π)\mathcal{L}(\pi) as the number of inversions of π\pi, i.e. $\displaystyle \mathcal{L}(\pi)=\sum_{1\le i\lt j\le n}[\pi(i)\gt \pi(j)]$。Compute $\displaystyle \frac{1}{|S|}\sum_{\pi \in S} \mathcal{L}(\pi)$。

Output the answer modulo (109+7)(10^9+7)。

Input Format

The first line contains two positive integers K,NK, N。

The next KK lines each contain NN positive integers describing πi\pi_i。

Output Format

Output one integer: the answer modulo (109+7)(10^9+7)。

1 3
2 3 1
333333337
2 5
4 2 1 3 5
2 5 4 3 1
5
1 9
3 4 5 6 7 8 1 9 2
300000017

Hint

Sample Explanation

  • Sample 11: S={[2,3,1],[3,1,2],[1,2,3]}S=\{[2,3,1],[3,1,2],[1,2,3]\}。The expected number of inversions is 1+2+03=43\frac{1+2+0}{3}=\frac{4}{3}。
  • Sample 22: It can be proven that ∣S∣=5!|S| = 5!, meaning that SS contains all permutations of 1∼51 \sim 5。
  • Sample 33: Here ∣S∣=20|S|=20。The true value of the answer is 14910\frac{149}{10}。

Constraints

For 100%100\% of the testdata, it is guaranteed that:

  • 1≤K≤101 \le K \le 10;
  • 1≤N≤2 5001 \le N \le 2\, 500;
  • πi\pi_i is a permutation of 1∼N1 \sim N。
Subtask ID N≤N\le K≤K\le Special Property Score
1 1 99 10 10 None 7 7
2 2 2 5002\,500 11 Yes 8 8
3 3 2 5002\, 500 None 25 25
4 4 1010 60 60

Special Property: for all 1≤i≤K1 \le i \le K, there exists a permutation aa of 1∼N1 \sim N such that $\pi_i(a_1)=a_2,\pi_{i}(a_2)=a_3,\cdots,\pi_i(a_n)=a_1$。

Translated by ChatGPT 5