I am trying to compute the number of nxm binary matrices with at most k consecutive values of 1 in each column. After a few researches, I've figured out that it will be enough to find the vectors with 1 column and n lines. For example, if we have p number of vectors the required number of matrices would be m^p. Because n and m are very large (< 2.000.000) i can't find a suitable solution. I am trying to find a recurrence formula in order to build a matrix to help me compute the answer. So could you suggest me any solution?
Asked
Active
Viewed 160 times
0
-
I think you meant `p^m` there – Niklas B. Mar 19 '14 at 20:53
-
Also what is the range for `k`? – Niklas B. Mar 19 '14 at 20:55
-
Yes you're right p^m. K < 50 – user3439480 Mar 20 '14 at 10:47
-
In that case David's answer should be a worthwhile approach – Niklas B. Mar 20 '14 at 15:08
1 Answers
1
There's a (k + 1)-state dynamic program (state = number of previous 1s, from 0 to k). To make a long story short, you can compute large terms of it quickly by taking the nth power of the k + 1 by k + 1 integer matrix like (example for k = 4)
1 1 0 0 0
1 0 1 0 0
1 0 0 1 0
1 0 0 0 1
1 0 0 0 0
modulo c and summing the first row.

David Eisenstat
- 64,237
- 7
- 60
- 120