This is related to this question, but I also want the corresponding complement ordered list that contains the element not chosen in an efficient way using python or c++. For example, with an ordered list list=(0,1,1,2,3,3)
when we choose 3 elements, one possible return pair should be (0,1,3)
and (1,2,3)
. Additionally, I want the function to return a total of C(n,k) terms, so that the pair (0,1,3)
and (1,2,3)
should repeat 4 times in the returned result.
Full example of a short input: define a function foo(list,k)
, then foo([0,1,1],1)
should return a list r
of length C(3,1)=3,
r(0)=[[0],[1,1]] (choose 0, complement list is [1,1])
r(1)=[[1],[0,1]] (choose first 1, complement list is [0,1])
r(2)=[[1],[0,1]] (choose second 1, complement list is [0,1])