// test_combine.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
const int MAXSIZE = 5;
int a[MAXSIZE] = {1,2,3,4,5};
vector<int> vec;
void combineNUM(int num,int index)
{
if (num == 0)
{
for (int i = 0 ; i < vec.size() ; i++)
{
cout << vec[i] << " ";
}
cout << endl;
return;
}
if (index == MAXSIZE)
{
return;
}
vec.push_back(a[index]);
combineNUM(num - 1,index + 1);
vec.pop_back();
combineNUM(num,index + 1);
}
void combine()
{
int num = 1 ; //num个数的组合
for (num = 1; num <= MAXSIZE ; num++ )
{
combineNUM(num,0);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
combine();
return 0;
}