Files
python/TangDou/LanQiaoBei/ZhongGaoJi/LanQiao14STEMA202303/BC4.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

42 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, ans, st[N];
int a[N][N];
bool check(int u) {
for (int i = 1; i < u; i++)
if (st[i] && a[u][i]) return false;
return true;
}
void dfs(int u, int sum) { // 第u号钻石,之前一共选了sum个钻石
if (u == n + 1) { // 如果所有钻石都找完了
ans = max(ans, sum); // 取最大值
return;
}
// 如果剩下的钻石都选也没有已有的最好情况多,返回,剪枝
// if (ans > sum + (n - u + 1)) return;
if (check(u)) { // 当前钻石与已选钻石没有冲突
st[u] = 1; // 选之
dfs(u + 1, sum + 1); // 继续下一个钻石
st[u] = 0; // 不选
}
dfs(u + 1, sum); // 继续下一个钻石
}
int main() {
cin >> n >> m;
while (m--) {
int x, y;
cin >> x >> y;
a[x][y] = a[y][x] = 1; // x<->y互相冲突
}
dfs(1, 0); // 从第一个钻石开始选,目前已选0个
cout << ans << endl;
return 0;
}