You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <iostream>
# include <algorithm>
# include <vector>
using namespace std ;
//算法: https://blog.csdn.net/wumuzi520/article/details/8087501#comments
void Combination ( int arr [ ] , int nLen , int m , int out [ ] , int outLen )
{
if ( m = = 0 )
{
for ( int j = 0 ; j < outLen ; j + + )
cout < < out [ j ] < < " \t " ;
cout < < endl ;
return ;
}
for ( int i = nLen ; i > = m ; - - i ) //从后往前依次选定一个
{
out [ m - 1 ] = arr [ i - 1 ] ; //选定一个后
Combination ( arr , i - 1 , m - 1 , out , outLen ) ; // 从前i-1个里面选取m-1个进行递归
}
}
void PrintCombination ( int arr [ ] , int nLen , int m )
{
if ( m > nLen )
return ;
int * out = new int [ m ] ;
Combination ( arr , nLen , m , out , m ) ;
delete [ ] out ;
}
int main ( ) {
int array [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ;
PrintCombination ( array , 6 , 3 ) ;
return 0 ;
}