Whats wrong with my solution for problem E : https://codeforces.me/contest/1342/problem/E?
Let c = n-k. Number of ways such that c columns are filled = (Number of ways such that <= c columns are filled) — (Number of ways such that <= c-1 columns are filled)
So formula is $$$ \binom{n}{c}c^n - \binom{n}{c-1}(c-1)^n $$$