I have N vectors which look like this:
[1→m] [m+1→2m] [2m+1→3m] [3m+1→4m] [4m+1→5m]..... [{(N-1)m}+1→Nm]
I want to select 1 element from each vector without duplication of any combinations.
Essentially only when all combinations are done with 1st element in first vector ,only then it should move to next element in first vector
say i have elements :[123] [456] [789]
my combinations should be like
147
148
149
157
158
159
167
168
169
247….
Also, i need no repetitions and only after all combinations of 1 are done only then the loop has to move to next combination ie 247 combination and so on.
i tried NCK (n choose k) command but it gave me random combinations.
how should i go about it with using minimal for loops
Basically you need to compute m^N elements. This means that you need N for loops, from 1 to m. Obviously this is not ideal if N is large, or if you don't know N at compile time. I would suggest an iterative approach. Create a vector of vectors of ints, and initialize it with vector<int>(1,1), vector<int>(1,2)... ,vector<int>(1,m). Then write a function that takes this vector of vectors and an integer step, that replace each element with m new vectors by taking each vector at step p and adding all combinations [pm+1->(p+1)*m]