Re: mathematical combination



On Nov 21, 11:44 am, keny...@xxxxxxxxx wrote:
Hi!
I'm new to C++ but I have a challenge to write a program to find the
different mathematical combinations of p and t objects respectively
from a total of n objects i.e. nCp and nCt.The program should display
the various combinations.
A further aspect is to find the intersection between nCp and nCt
i.e.each set of nCp that contains each of the possible combinations of
nCt without considering the order of appearance.
Let me try to be clearer,pls:
say n=7,p=5 and t=3
1. I want a program to find 7C5 and 7C3
2. I want a display of the possible combinations in each case i.e
for 7C5; (12345),(12346),(12347),(13456)etc and
for 7C3; (123),(124),(125),(126)etc
3. Finally, the intersection e.g.
(123) intersects (12345),(12346),...
(124) intersects (12345),(12346)...
(125) intersects (12345)
and so on.
Your help will be appreciated.Thanks.

Or take the list, sort it using the STL sort algorithm, then use
next_permutation to get all permutations of the numbers up to n. Then
take the sub length and add it to a set<vector<int>>, eliminating
duplicates. This approach works well. I had a better way when I was
working in an abstract algebra course . . . hmmm.

Then using set_intersection to get the intersection of the vectors in
the set.

This might require some research of the STL, but it makes things easy.
.