Combination under constrained situation with a condition
Step 1: I want to take a number n
as input from user
Step 2: We form the set S
consisting of elements from 0
to n*(2^{n-1})
Step 3: Now I pick each possible two-element subsets of S
and store it in P
.
Step 4: Now I need to pick n*(2^{n-1})
two-element subsets from P
such that each number that occurs in that set occurs exactly n
times
neither less nor more and put them all in a list.
Example
n = 2
n*(2^{n-1}) = 2*(2^{2-1}) = 4
S = {0,1,2,3,4}
p = {(0,1),(0,2),(0,3),(0,4),(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)}
Step 4 One element which satisfies condition of step 4; HERE n = 2
.
{(0,1),(1,2),(2,3),(0,3)}
which has 2*(2^{n-1}) = 2*(2^{2-1}) = 4
elements.
Now see in the above set
0
occurredn=2
times only in(0,1)
and(0,3)
only1
occurredn=2
times only in(0,1)
and(1,2)
only2
occurredn=2
times only in(1,2)
and(2,3)
only3
occurredn=2
times only in(2,3)
and(0,3)
only
Similarly we may get for {(0,1),(1,4),(4,2),(2,0)}
we can easily verify like above.
Now based on n
the number of elements size etc will vary.
Kindly help if possible any one.