2 , .. 2 * N .
- , n [] , :
a = 0, b = 1, c = 0, d = 1
a = 1, b = 1, c = 0, d = 0
...
n [a + b + c + d] n [2] C (4,2) ..
, .
.
But if anything - I would go with the backtracking (recursion) method if this is really what the user wants. (especially if there are N dimensions - since there is no real great way to do this thing iteratively if you don't want to use dp on this, which is probably above the end-user’s head)
tperk source
share