forked from silent-killer-11/Hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcircular_queue.cpp
More file actions
59 lines (48 loc) · 1.14 KB
/
circular_queue.cpp
File metadata and controls
59 lines (48 loc) · 1.14 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
// All possible moves of the knight.
// In X axis.
vector<int> X = { 2, 1, -1, -2, -2, -1, 1, 2 };
// In Y axis.
vector<int> Y = { 1, 2, 2, 1, -1, -2, -2, -1 };
void getCountRec(vector<vector<bool> >& board,
int i, int j, int n)
{
// if n=0, we have our result.
if (n == 0)
return;
for (int k = 0; k < 8; k++) {
int p = i + X[k];
int q = j + Y[k];
// Condition for valid cells.
if (p >= 0 && q >= 0
&& p < 10 && q < N) {
board[p][q] = true;
getCountRec(board, p, q, n - 1);
}
}
}
int getCount(int i, int j, int n)
{
vector<vector<bool> > board(N, vector<bool>(N));
board[i][j] = true;
// Call the recursive function to mark
// visited cells.
getCountRec(board, i, j, n);
int cnt = 0;
for (auto row : board) {
for (auto cell : row) {
if (cell)
cnt++;
}
}
return cnt;
}
// Driver Code
int main()
{
int i = 3, j = 3, N = 2;
cout << getCount(i, j, N) << endl;
return 0;
}