Wolfram Language (Mathematica), 4949 32 bytes
PositionIndex@Tuples[0|0|1|1,#]&
Returns an Association
where the values correspond with rows of the matrix (associations are ordered). For a traditional list-of-lists output, prepend List@@
(+6 bytes).
Port of Lynn's Jelly solution.
Older solution:
Outer[#+##&,t=#~FromDigits~4&/@{0,1}~Tuples~#,t]&
Fold[3#+##&]
would save 3 bytes over #~FromDigits~4
, but fails to correctly handle n=0
: Try it online!