'commit'
This commit is contained in:
38
TangDou/Mkx/202412C1/8741_2.cpp
Normal file
38
TangDou/Mkx/202412C1/8741_2.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 15;
|
||||
int n, ans, color[N];
|
||||
|
||||
// N个公共边
|
||||
struct Node {
|
||||
int x, y;
|
||||
} a[N];
|
||||
|
||||
void dfs(int u) {
|
||||
if (u > 5) { // 判断
|
||||
bool flag = true;
|
||||
// 检查此时的安排是不是合理
|
||||
for (int i = 1; i <= n; i++) { // 遍历每个公共边
|
||||
if (color[a[i].x] == color[a[i].y]) { // 如果两个区域的颜色相同,则返回
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) ans++; // 找到了一个新方案
|
||||
return;
|
||||
}
|
||||
// 枚举方案
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
color[u] = i; // u这个区域放i这个颜色
|
||||
dfs(u + 1); // 走到下一个区域面前
|
||||
}
|
||||
}
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; // 区域x与区域y之间存在公共边
|
||||
// 开始搜索
|
||||
dfs(1);
|
||||
// 输出结果
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user