Google APAC TEST Dynamic programming

I have seen few solutions and they are using following relation:
f(m, n) = (f(m - 1, n - 1) * m) % MOD + (f(m, n - 1) * (M - m)) % MOD

How to reach this equation?

1 Like

i think it is a variation of problem of finding the number of solution set of equation x1+x2+…+xr=n.
similar question was asked in TechFest2015,portal round
how to approach such type of problems?