1 条题解
-
0大金狮 (mengqingyu) LV 10 @ 2024-12-7 18:09:15
100行代码🎭表演**
AC**#include<bits/stdc++.h> using namespace std; const int M = 70; int T, n, tot, k, depth; bool v[M], kv[M]; vector<int> e[M]; inline void build() { memset(v, false, sizeof(v)); tot = 0; scanf("%d", &n); int delta = 2 * n + 1; for (int len = 1; len <= n; len++) for (int a = 1; a + len <= n + 1; a++) for (int b = 1; b + len <= n + 1; b++) { e[tot].clear(); for (int i = 0; i < len; i++) { e[tot].push_back(a + (b - 1) * delta + i); e[tot].push_back(a + (b + len - 1) * delta + i); e[tot].push_back(delta * (b - 1 + i) + n + a); e[tot].push_back(delta * (b - 1 + i) + n + a + len); } tot++; } scanf("%d", &k); while (k--) { int x; scanf("%d", &x); v[x] = true; } } inline int f() { memcpy(kv, v, sizeof(v)); int cnt = 0; for (int i = 0; i < tot; i++) { bool flag = true; for (auto &it:e[i]) if (v[it]) { flag = false; break; } if (flag) { cnt++; for (auto &it:e[i]) v[it] = true; } } memcpy(v, kv, sizeof(v)); return cnt; } inline bool check() { for (int i = 0; i < tot; i++) { bool flag = true; for (auto &it:e[i]) if (v[it]) { flag = false; break; } if (flag)return false; } return true; } bool dfs(int d) { if (d + f() > depth)return false; if (check())return true; for (int i = 0; i < tot; i++) { bool flag = true; for (auto &it:e[i]) { flag = true; if (v[it]) { flag = false; break; } } if (flag) { for (auto &it:e[i]) { v[it] = true; if (dfs(d + 1))return true; v[it] = false; } break; } } return false; } int main() { cin >> T; while (T--) { build(); depth = 0; while (!dfs(0))depth++; printf("%d\n", depth); } return 0; }
- 1
信息
- ID
- 93
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 19
- 已通过
- 10
- 上传者