I have a $n \times m$ matrix $M$ and a permutation of sequence $P$ of numbers from $1$ to $n$.
I have to fill the matrix using numbers $1$ to $n \times m$ in such a way that for each row $i$, the function $f(i) > 0.5$ where:
$f(i)$ is the probability that a number chosen randomly from row $i$ will be greater than a number chosen randomly from row $P[i]$. ($i$'s corresponding row according to permutation.)
For an example, let $n=3$,$m=3$,$P=[3, 1, 2]$ and $M=$
2 6 7
3 4 8
1 5 9
According to the given permutation, you will have to compare the number chosen from 1st row with 3rd row and similarly.
In the given matrix number are arranged in such a way that $f(1) = f(2) = f(3) = 5/9$. Observe that there are 5 pairs in the Cartesian product $\{2,6,7\}\times\{1,5,9\}$ which the first element is larger than the second.
My question is how to construct such a matrix provided $n,m,P$ as input?