# How to determine a matrix when the sums of rows and columns are given

I was given a $5\times30$ matrix with each element of the matrix can only take 0 or 1.

It is given that the sum of each row is 8 and the sum of the first 20 columns equals to 1 while the sum of each rest 10 columns equals to 2.

Can anyone know how to find all possible matrices that fulfils these conditions? For example, any R algorithm can be ran for this goal?

• What is the size of your matrix again? $5\times 28$ ? – Kushal Bhuyan May 10 '16 at 16:35
• The total number of 1s is 40 if you look at the rows, but 20+16 if you look at the columns! – almagest May 10 '16 at 16:38
• @almagest Sorry, I have changed the size of the matrix, now the sum of all columns and the sum of all rows are equal. – user99015 May 10 '16 at 16:54
• @KushalBhuyan It is $5\times30$ – user99015 May 10 '16 at 17:14
• I have built on a very similar theme a probabilistic program using a MCMC (Markov Chain Monte Carlo) exploration, that in fact was exhaustive, with a moderate number of lines in Matlab (that is not fundamentally different from R). I will try to retrieve this code and possibly adapt it. I believe that in fact you are less interested by the solutions themselves than by their number, isn't it ? – Jean Marie May 10 '16 at 18:14