题目描述
blablabla
样例
blablabla
算法1
(dfs) $O(n^2)$
blablabla
C++ 代码
#include<iostream>
using namespace std;
int n;
int path[20];
bool st[20];
void dfs(int pos, int start, int tar)
{
if(pos == tar)
{
for(int i = 1;i <= tar; i ++ )cout << path[i] << " ";
cout << endl;
return;
}
for(int i = start; i <= n; i ++ )
{
if(!st[i])
{
st[i] = true;
path[pos+1] = i;
dfs(pos+1,i+1,tar);
st[i] = false;
}
}
}
int main()
{
cout << endl;
cin >> n;
for(int i = 1; i <= n; i ++ )
{
dfs(0,1,i);
}
return 0;
}