样例输入:
3 4
样例输出:
4 3 2
4 3 1
4 2 1
3 2 1
AC代码
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int m,n;
vector<int>hashtable;
vector<int>ans;
void toarray(int index)
{
if(index==3)
{
for(int i=0;i<3;i++)
{
printf("%d ",ans[i]);
}
printf("\n");
return ;
}
for(int i=n;i>=1;i--)
{
if(hashtable[i]==0&&(ans.size()==0||i<ans[ans.size()-1]))
{
hashtable[i]=1;
ans.push_back(i);
toarray(index+1);
ans.pop_back();
hashtable[i]=0;
}
}
}
int main()
{
scanf("%d%d",&m,&n);
hashtable.resize(n+1);
fill(hashtable.begin(),hashtable.end(),0);
toarray(0);
}