Help on a problem from IOPC, IIT Kanpur

Can anyone help me with the solution of this problem?

My approach: Solve the problem of counting distribution types in a city by formulating it as a coin change problem. So, we construct a dp array of size n+m-1. Solving it for the paramterers(all coins valued upto n+m-1 from 1 and the total value is n+m-1 ) gives me an n^2 dp solution. Which is not passing the time limits…
What should be the approach then?
Thanks if anyone find time to help me…