-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15649.cpp
More file actions
39 lines (36 loc) · 716 Bytes
/
Copy path15649.cpp
File metadata and controls
39 lines (36 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define MAX_SIZE 9
using namespace std ;
int M, N ;
int arr[MAX_SIZE] ;
bool visited[MAX_SIZE] ;
void BackTracking(int index)
{
if(index == M)
{
for(int i = 0 ; i < index ; i++)
cout << arr[i] << " " ;
cout << endl ;
}
else
{
for(int i = 1 ; i <= N ; i++)
{
if(!visited[i])
{
visited[i] = 1 ;
arr[index] = i ;
BackTracking(index+1) ;
visited[i] = 0 ;
}
}
}
}
int main()
{
SETTING ;
cin >> N >> M ;
BackTracking(0) ;
}