博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 2466: [中山市选2009]树 [高斯消元]
阅读量:4544 次
发布时间:2019-06-08

本文共 1295 字,大约阅读时间需要 4 分钟。

题意:开关上树


见到拿高斯消元胡就行了

#include 
#include
#include
#include
#include
#include
using namespace std;typedef unsigned long long ll;const int N=105;inline int read() { char c=getchar(); int x=0, f=1; while(c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();} while(c>='0' && c<='9') {x=x*10+c-'0'; c=getchar();} return x*f;}int n, u, v;bitset
a[N];int now, pivot[N], li[N], val[N];void gauss() { now=1; for(int i=1; i<=n; i++) { int j=now; while(j<=n && !a[j][i]) j++; if(j==n+1) {li[++li[0]] = i; continue;} if(j!=now) swap(a[now], a[j]); for(int j=1; j<=n; j++) if(a[j][i] && j!=now) a[j] ^= a[now]; pivot[i] = now; now++; } now--;}int ans;void dfs(int d, int tot) { //printf("dfs %d %d\n",d,tot); if(d==0) {ans = min(ans, tot); return;} if(tot >= ans) return; if(pivot[d]) { bitset
&t = a[pivot[d]]; int x = t[n+1]; for(int i=1; i<=li[0]; i++) if(t[li[i]]) x ^= val[li[i]]; dfs(d-1, tot+x); } else { val[d]=0; dfs(d-1, tot); val[d]=1; dfs(d-1, tot+1); }}int main() { freopen("in","r",stdin); while(true) { n=read(); if(n==0) break; for(int i=1; i<=n; i++) a[i].reset(); memset(pivot, 0, sizeof(pivot)); memset(li, 0, sizeof(li)); ans=n; for(int i=1; i

转载于:https://www.cnblogs.com/candy99/p/6660293.html

你可能感兴趣的文章
CSS3圆角详解(border-radius)
查看>>
Python正则表达式指南
查看>>
前端学习之JavaScript中的 NaN 与 isNaN
查看>>
chrome安装json view插件
查看>>
CSS div 高度满屏
查看>>
页面回发速度由 6 秒减少为 0.6 秒的真实案例!
查看>>
一种实现C++反射功能的想法(一)
查看>>
lvs+keepalived+nginx高性能负载均衡集群
查看>>
XXL-Job高可用集群搭建
查看>>
JDBC
查看>>
Python replace()方法
查看>>
Kestrel: System.Exception: Error -4092 EACCES permission denied
查看>>
mysql select
查看>>
Nginx学习——Nginx进程间的通信
查看>>
5.2 上午
查看>>
[LintCode] Sort Integers 整数排序
查看>>
71. Simplify Path
查看>>
CodeForces - 123E Maze
查看>>
ZOJ 1709 Oil Deposits(dfs,连通块个数)
查看>>
安卓开源项目周报0308
查看>>