[BZOJ1770][Usaco2009 Nov]lights 燈(高斯消元)
来源:互联网 发布:gta5韩国美女捏脸数据 编辑:程序博客网 时间:2024/05/07 07:01
题目描述
传送门
题解
orz繁體中文
高斯消元解異或方程組
最後需要暴搜自由元
一定要加一个最简单的最优化剪枝,否则会tle…
代码
#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#include<bitset>using namespace std;int n,m,x,y,now,Min=35;int tot,point[40],nxt[1200],v[1200];int b[40],ans[40];bitset <40> a[40];void add(int x,int y){ ++tot; nxt[tot]=point[x]; point[x]=tot; v[tot]=y;}void dfs(int dep){ if (!dep) { Min=min(Min,now); return; } if (now>=Min) return; if (a[dep][dep]) { for (int i=dep+1;i<=n;++i) if (a[dep][i]) b[dep]^=ans[i]; ans[dep]=b[dep]; if (ans[dep]) ++now; dfs(dep-1); if (ans[dep]) --now; for (int i=dep+1;i<=n;++i) if (a[dep][i]) b[dep]^=ans[i]; } else { ans[dep]=0; dfs(dep-1); ans[dep]=1; ++now; dfs(dep-1); --now; }}void gauss(){ for (int i=1;i<=n;++i) { if (!a[i][i]) { int num=i; for (int j=i+1;j<=n;++j) if (a[j][i]) {num=j;break;} a[i]^=a[num],b[i]^=b[num]; } for (int j=i+1;j<=n;++j) if (a[j][i]) a[j]^=a[i],b[j]^=b[i]; } dfs(n);}int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=m;++i) { scanf("%d%d",&x,&y); add(x,y),add(y,x); } for (int i=1;i<=n;++i) { a[i][i]=b[i]=1; for (int j=point[i];j;j=nxt[j]) a[i][v[j]]=1; } gauss(); printf("%d\n",Min);}
0 0
- [BZOJ1770][Usaco2009 Nov]lights 燈(高斯消元)
- bzoj1770[Usaco2009 Nov]lights 燈 高斯消元
- bzoj1770[Usaco2009 Nov]lights 燈
- BZOJ1770: [Usaco2009 Nov]lights 燈(异或方程组)
- BZOJ1770: [Usaco2009 Nov]lights 灯
- bzoj1770: [Usaco2009 Nov]lights 灯
- [Usaco2009 Nov]lights 燈
- bzoj 1770: [Usaco2009 Nov]lights 燈 (高斯消元)
- 【高斯消元】BZOJ 1770: [Usaco2009 Nov]lights 燈
- 1001: [Usaco2009 Nov]lights 燈
- BZOJ 1770: [Usaco2009 Nov]lights 燈
- BZOJ 1770 [Usaco2009 Nov] lights 燈
- bzoj 1770 [Usaco2009 Nov]lights 燈
- bzoj 1770: [Usaco2009 Nov]lights 燈
- 1770: [Usaco2009 Nov]lights 燈 高斯消元解异或方程组+dfs
- bzoj 1770/Luogu 2962 [Usaco2009 Nov]lights 燈
- [BZOJ]1770: [Usaco2009 Nov]lights 燈 高斯消元解xor方程组
- 【BZOJ】1770 [Usaco2009 Nov]lights 燈 折半搜索
- defer、async属性以及JS异步加载并执行解决方案
- LeetCode之Merge two sorted array
- defer、async属性以及JS异步加载并执行解决方案
- [翻译自MOS文章]怎么在OGG 12c版本中把replicat进程重新定位到之前的trail文件位置上?
- 如何查看Struts2的action情况
- [BZOJ1770][Usaco2009 Nov]lights 燈(高斯消元)
- 基础练习 芯片测试
- 复数类-简单的运算符重载
- Educational Codeforces Round 17-D. Maximum path
- poj2528 离散线段树
- 【t072】国际象棋
- 机器学习算法中如何选取超参数:学习速率、正则项系数、minibatch size
- Shell编程之变量
- vue 学习第二节