L, O], [D, F, K, O], etc., please use the back in the search algorithm, according to the required output:
Length of 0 subset are: 1
Length of 1 subsets are: 7
Length is a subset of the 2:21
Length is 3 a subset of the...
...
Length is 6 subset are: 7
Length is 7 subset are: 1
CodePudding user response:
# include & lt; Vector>
# include & lt; Iostream>
Void BackTrackSubArrays (STD: : vector& VecTemp, size_t & amp; NCount, size_t nTotal, size_t nBegin, const STD: : vector & VecArray)
{
If (vecTemp. The size ()==nTotal)
{
+ + nCount;
return;
}
For (size_t I=nBegin; I & lt; VecArray. The size (); I++)
{
VecTemp. Push_back (vecArray [I]);
BackTrackSubArrays (vecTemp, nCount nTotal, I + 1, vecArray);
VecTemp. Pop_back ();
}
}
Void SubArrays (const STD: : vector& VecArray)
{
STD: : vectorVecTemp;
VecTemp. Reserve (vecArray. The size ());
Size_t nCount=0;
For (size_t I=0; I & lt;=vecArray. The size (); I++)
{
BackTrackSubArrays (vecTemp, nCount, I, 0, vecArray);
STD: : cout & lt; <"Length" & lt; NCount=0;
}
}
Int main ()
{
SubArrays ({' A ', 'D', 'F' and 'Z', 'K', 'L', 'O'});//use c + + 11 initializes the syntax here, if the compiler doesn't support c + + 11, please your STD: : vectorEnter
system("pause");
return 0;
}