I have a set of n case in the format a b what I have to do is I have to form number of distinct combination of numbers from a,b. for e.g.,
suppose n=4 and a,b are are follow
1 2
3 1
2 4
3 2
Now total there are 4 distinct number by seeing a,b, they are(1,2,3,4)
and two combination of all distinct numbers can be formed, they are (1,3,4,2) and (2,1,4,3) as follow :-
1 2
|
3 1
\
2 4
|
3 2
and
1 2
|
3 1
|
2 4
/
3 2
My problem is I am unable to think how to code, as n<=50 and a,b<=16 so I am not sure that how many distinct number can be there, if there are 16 numbers then I have to find all possible combination of 16 numbers, so guide me through this.
To form a list of distinct numbers just use a "unique set" and keep inserting all the numbers to it. In C++, std::set by definition stores only unique numbers.
To find the number of combinations of distinct sequences, you will have to keep a list of "candidate lists" and keep inserting numbers in them if they already don't have those numbers, else delete that particular candidate list.
Full code in C++:
Input: 1 2 3 1 2 4 3 2
Output: The unique list: 1 2 3 4 Total number of combinations: 2