백준 15650 c++
#include <iostream>
//다시 하기
using namespace std;
int n, m;
int arr[9] = { 0, };
bool visited[9] = { 0, };
int input(int lower, int upper)
{
//cout << "input()" << endl;
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
void dfs(int num, int cnt)
{
int i;
if (cnt == m)
{
for (int i = 0; i < m; i++)
{
cout << arr[i] << " ";
}
cout << "\n";
return;
}
else
{
for (i = num; i <= n; i++)
{
if (!visited[i])
{
visited[i] = true;
arr[cnt] = i;
dfs(i + 1, cnt + 1);
visited[i] = false;
}
}
}
return;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
n = input(1, 8);
m = input(1, n);
dfs(1, 0);
return 0;
}