Algorithm for distribution of numbers in a matrix
<p>This is my first question on stack exchange. I'm working on a problem where I need to find a distribution of non-negative integers in a matrix where each row and each column adds up to a target total. I am sure there is an algorithm that can do this (or a theory that says when this is possible and when it is not) but I haven't had much luck finding this online.</p>

<p>In the attached image (<a href="https://i.stack.imgur.com/Yn9El.png" rel="nofollow">Image</a>) I have an example of a solution that I found for a specific instance of the problem but there was no definable algorithm involved. The grey totals are the target totals for each column and row while the light blue totals are the totals for the current distribution shown. At the beginning of the algorithm only the totals are provided so I start with an empty matrix.</p>

<p>Could someone please point me to a resource/solution for this problem?</p>

<p>Thank you</p>