Hi 🖐️ I am Avinash.
- Welcome to my blog. I write about math here.
- I write about programming here.
Hi 🖐️ I am Avinash.
A Little Background I was trying to solve this problem on SPOJ. It’s a dynamic-programming problem. I tried to find some recursive relation. I spent hours. But no breakthrough. I even tried looking for hints in comments and I came to know it’s a 3D dynamic-programming problem. Some of the users were even able to reduce it to a 2D technique. Then I realized I need to rethink the entire approach....
Problem Find the number of integer solutions i.e. ordered pairs $\left(x_1, x_2, \ldots , x_r \right)$ such that $$x_1 + x_2 + \ldots + x_r = n, \quad x_i \geq 0, x_i \in \mathbb{Z}$$ Solution The number of such solutions is given by $${^{n+r-1}C_{r-1}} = \frac{\left( n+r-1 \right)!}{ n! \left( r-1 \right)!}$$