-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlackBook117.cpp
More file actions
59 lines (54 loc) · 1.05 KB
/
BlackBook117.cpp
File metadata and controls
59 lines (54 loc) · 1.05 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 <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int MAX_N = 107;
int n;
int List[MAX_N];
char str[MAX_N];
bool e[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];
vector<int> ans;
bool Meet(int a, int b) {
if (~dp[a][b]) return dp[a][b];
if (a + 1 == b) return dp[a][b] = 1;
int can = false;
for (int i = a + 1; i < b; ++i) {
if ((e[List[a]][List[i]] || e[List[b]][List[i]]) && Meet(a, i) && Meet(i, b)) {
can = true;
break;
}
}
return dp[a][b] = can;
}
int main() {
int T;
scanf("%d", &T);
while (T-- > 0) {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%s", str + 1);
for (int j = 1; j <= n; ++j) {
e[i][j] = str[j] == '1';
}
}
ans.clear();
for (int i = 1; i <= n; ++i) {
memset(dp, -1, sizeof dp);
int t = i;
for (int j = 0; j <= n; ++j) {
if (t <= n) List[j] = t;
else List[j] = t - n;
++t;
}
if (Meet(0, n))
ans.push_back(i);
}
int len = (int) ans.size();
printf("%d\n", len);
for (int i = 0; i < len; ++i) {
printf("%d\n", ans[i]);
}
}
return 0;
}