-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA02003.cpp
More file actions
56 lines (48 loc) · 1.01 KB
/
Copy pathDSA02003.cpp
File metadata and controls
56 lines (48 loc) · 1.01 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
// https://code.ptit.edu.vn/student/question/DSA02003
// DI CHUYỂN TRONG MÊ CUNG 1
#include <bits/stdc++.h>
using namespace std;
int n, a[11][11];
vector<string> v;
void Try(int i, int j, string s) {
if (i == n && j == n) {
v.push_back(s);
return;
}
if (i < n && a[i + 1][j] == 1)
Try(i + 1, j, s + 'D');
if (j < n && a[i][j + 1] == 1)
Try(i, j + 1, s + 'R');
}
void TestCase() {
v.clear();
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
}
}
if (a[1][1] == 0 || a[n][n] == 0) {
cout << "-1\n";
return;
}
Try(1, 1, "");
if (v.empty()) {
cout << "-1\n";
return;
}
sort(v.begin(), v.end());
for (auto x : v) {
cout << x << " ";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int T; cin >> T;
while (T--) {
TestCase();
cout << endl;
}
return 0;
}