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.
|
|
|
|
#include <iostream>
|
|
|
|
|
#include<algorithm>
|
|
|
|
|
#include<vector>
|
|
|
|
|
using namespace std;
|
|
|
|
|
//<2F>㷨<EFBFBD><E3B7A8>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) //<2F>Ӻ<EFBFBD><D3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB>
|
|
|
|
|
{
|
|
|
|
|
out[m-1] = arr[i-1]; //ѡ<><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|
|
|
|
Combination(arr,i-1,m-1,out,outLen); // <20><>ǰi-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡȡm-1<><31><EFBFBD><EFBFBD><EFBFBD>еݹ<D0B5>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|