Number of pair of sequences of length $n$ such that no $2$ elements are equal

53 Views Asked by At

My question is this :

Given two integers $n$ and $k$, we have to generate $2$ sequences $A$ and $B$ of length $n$ each containing integers from $1$ to $k$. Find the number of sequences we can generate such that no corresponding element of sequences are equal. Formally: for each $i$ from $1$ to $n$ $: A_i \neq B_i$

1

There are 1 best solutions below

3
On BEST ANSWER

For each element of $A$ you have $k$ choices, so there are $k^n$ possibilities. Given $A$, for each element of $B$ you have $k-1$ choices, so there are $(k-1)^n$ possibilities. There are therefore $k^n(k-1)^n$ pairs possible.