What basically I am doing is the set cover problem, removing duplicate from the vectors that has the same numbers. An example:
I have the following vectors of vectors after sorting:
{{1,2,3,4,5},{2,3,7,8},{10,11,12}}
NOW, I would like to remove the occurrence from 2nd vector which is 2,3 and sort again …
{{1,2,3,4,5},{10,11,12},{7,8}}
I have implemented some code to sort the vectors of vectors but i have problem removing the occurrences from the vector that has less size?
The sort function:
sort(ROWS.begin(),ROWS.end(),VectorsSort());
Thanks for the help.
Pick this apart and take what you need:
(Note that
set_coverrequires that the containedstd::vector<int>s given must already be sorted.)EDIT #1:
As requested in now-deleted comments, a version oriented around
std::map<int, std::vector<int>>instead ofstd::vector<std::vector<int>>(usebinary_search_predfrom the original code):Note that the
maphere will always be sorted by its key, never by the containedvector‘s size (which is what you appear to want). Maybe you want astd::vector<std::pair<int, std::vector<int>>>instead?EDIT #2:
As requested in now-deleted comments, a version oriented around
std::vector<std::pair<int, std::vector<int>>>instead ofstd::map<int, std::vector<int>>(usebinary_search_predfrom the original code):