[推荐][数学里面的组合问题][回溯法]
#include<iostream>
using namespace std;
const int N = 100;
void enumall(int n,int r)
{
int i,j,c[N];
for(j = 0; j<r;j++)
c[j]=j;
for(j=0;j<r;j++)
cout<<c[j]<<" ";
cout<<endl;
i = r-1;
do{
if(c[i]< n-r+i)
{
c[i]++;
for(j = i+1;j<r;j++)
c[j] = c[j-1]+1;
for(j=0;j<r;j++)
cout<<c[j]<<" ";
cout<<endl;
i = r-1;
}
else --i;
}while(i>=0);
}
int main()
{
enumall(5,3);
return 0;
}