#include <iostream>
using namespace std;
int combine(int a[], int n, int m)
{
m = m > n ? n : m;

int* order = new int[m+1];
for(int i=0; i<=m; i++)
order[i] = i-1;

int count = 0;
int k = m;
bool flag = true;
while(order[0] == -1)
{
if(flag)
{
for(int i=1; i<=m; i++)
{
cout << a[order[i]] << " ";
}
cout << endl;
count++;
flag = false;
}

order[k]++;
if(order[k] == n)
{
order[k--] = 0;
continue;
}

if(k < m)
{
order[++k] = order[k-1];
continue;
}

if(k == m)
flag = true;
}

delete[] order;
return count;
}

int main()
{
const int M = 3;
const int N = 2;
int a[M];
int b[N];
for(int i=0;i<M;i++)
a[i] = i+1;

cout<<combine(a,M,N)<<endl;
system("pause");
return 0;
}