#P9004. Counting Ordered Permutation Tuples with Lexicographical and Inversion Constraints
Counting Ordered Permutation Tuples with Lexicographical and Inversion Constraints
Counting Ordered Permutation Tuples with Lexicographical and Inversion Constraints
Given three positive integers n, m, and mod.
For each positive integer i (1 ≤ i ≤ n), consider all i-element permutations of {1,2,…,i}. Let these permutations be listed in lexicographical order (i.e. dictionary order). For each permutation, define its inversion count as the number of pairs (p, q) with 1 ≤ p < q ≤ i such that the element at position p is greater than the element at position q.
Now, for a fixed i and an integer j (1 ≤ j ≤ m), let f(i,j) be the number (modulo mod) of ordered j-tuples of distinct permutations (p1, p2, …, pj) chosen from the set of all i-permutations, satisfying:
- Lexicographical condition: p1 < p2 < … < pj (when compared as sequences in dictionary order).
- Inversion count condition: inv(p1) > inv(p2) > … > inv(pj), where inv(p) denotes the inversion count of permutation p.
You are to output the table of values f(i,j) modulo mod for all 1 ≤ i ≤ n and 1 ≤ j ≤ m. For each i from 1 to n, output one line containing m space‐separated integers: f(i,1), f(i,2), …, f(i,m). If no valid j-tuple exists then f(i,j) is 0.
Note: The permutations for each i are considered in lexicographical order. A valid j-tuple is equivalent to choosing a subset of j permutations (ordered increasingly by their lex order) for which their inversion counts form a strictly decreasing sequence.
inputFormat
The input consists of a single line with three integers n, m, and mod (1 ≤ n, m; mod ≥ 1).
outputFormat
Output n lines. The i-th line (1-indexed) should contain m integers separated by a space: f(i,1), f(i,2), …, f(i,m) computed modulo mod.
sample
1 1 100
1
</p>