参考:https://blog.csdn.net/qq_34564984/article/details/53843777 可能背了假的板子-- 对于每个灯建立方程:与它相邻的灯的开关次数的异或和为1 异或高斯消元,然后dfs,遇到自由元就分两种情况走,答案取max,加上最优性剪枝 #include<iostream> #include<cstdio> #include<cmath> using namespace std; const int N=45; int n,…
设$f[i]$表示$i$点按下开关后会影响到的点的集合,用二进制表示. 不妨设$n$为偶数,令$m=\frac{n}{2}$,对于前一半暴力$2^m$搜索所有方案,用map维护每种集合的最小代价. 对于后一半暴力$2^m$搜索所有方案,在map中查询补集. 时间复杂度$O(n2^{\frac{n}{2}})$. #include<cstdio> #include<map> #define N 36 typedef long long ll; int n,m,i,x,y,ans=N,…