File tree 2 files changed +73
-0
lines changed
2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " bits/stdc++.h"
2
+ using namespace std ;
3
+ #define ll long long int
4
+ #define endl " \n "
5
+
6
+ ll ans = 0 ;
7
+ bool ld[15 ], rd[15 ], row[7 ];
8
+ char board[8 ][8 ];
9
+
10
+ void rec (ll j)
11
+ {
12
+ if (j == 8 )
13
+ {
14
+ ans++;
15
+ return ;
16
+ }
17
+ for (ll i = 0 ; i < 8 ; i++)
18
+ {
19
+ if (board[i][j] == ' .' && ld[i - j + 7 ] == 0 && rd[i + j] == 0 && row[i] == 0 )
20
+ {
21
+ ld[i - j + 7 ] = 1 ;
22
+ rd[i + j] = 1 ;
23
+ row[i] = 1 ;
24
+ rec (j + 1 );
25
+ ld[i - j + 7 ] = 0 ;
26
+ rd[i + j] = 0 ;
27
+ row[i] = 0 ;
28
+ }
29
+ }
30
+ }
31
+
32
+ int main ()
33
+ {
34
+ ll i, j, n;
35
+ n = 8 ;
36
+ for (i = 0 ; i < n; i++)
37
+ {
38
+ for (j = 0 ; j < n; j++)
39
+ {
40
+ cin >> board[i][j];
41
+ }
42
+ }
43
+
44
+ rec (0 );
45
+
46
+ cout << ans << endl;
47
+ return 0 ;
48
+ }
Original file line number Diff line number Diff line change
1
+ #include " bits/stdc++.h"
2
+ using namespace std ;
3
+ #define ll long long int
4
+ #define endl " \n "
5
+
6
+ void recur (int x, int y, int z, int n)
7
+ {
8
+ if (n == 0 )
9
+ {
10
+ return ;
11
+ }
12
+ recur (x, z, y, n - 1 );
13
+ cout << x << " " << z << endl;
14
+ recur (y, x, z, n - 1 );
15
+ }
16
+
17
+ int main ()
18
+ {
19
+ int n;
20
+ cin >> n;
21
+ int k = pow (2 , n) - 1 ;
22
+ cout << k << endl;
23
+ recur (1 , 2 , 3 , n);
24
+ return 0 ;
25
+ }
You can’t perform that action at this time.
0 commit comments