2017/4/15 Twosat介绍
来源:互联网 发布:梦幻古龙服务端源码 编辑:程序博客网 时间:2024/05/23 02:00
Twosat讲解详见算法入门经典1 324页
贴出白书模板
struct TwoSAT{ int n; vector <int> G[maxn*2]; bool mark[maxn*2]; int S[maxn*2], c; bool dfs(int x){ if(mark[x^1]) return false; if(mark[x]) return true; mark[x] = true; S[c++] = x; for(int i = 0; i < G[x].size(); i++){ if(!dfs(G[x][i])) return false; } return true; } void init(int n){ this->n = n; for(int i = 0; i < n*2; i++) G[i].clear(); memset(mark, 0, sizeof(mark)); } void addedge(int x, int xval, int y, int yval){ x = x * 2 + xval; y = y * 2 + yval; G[x^1].push_back(y); G[y^1].push_back(x); } bool solve(){ for(int i = 0; i < 2*n; i += 2) if(!mark[i] && !mark[i+1]){ c = 0; if(!dfs(i)){//已经尝试过把i标记为true,然而不行,那么在尝试将i+1标记为真时,先把i的影响消掉 while(c > 0) mark[S[--c]] = false; if(!dfs(i + 1)) return false; } } return true; }}twosat;
例题推荐:
UVALIVE 3211 二分+TwoSAT
UVALIVE 3713 宇航员分组 TWOSAT
CF 766D TWOSAT http://blog.csdn.net/just_sort/article/details/60763945
0 0
- 2017/4/15 Twosat介绍
- TwoSat
- TwoSAT模版(LRJ)
- hdu 4751(twosat)
- hdu 3622 (twosat)
- LA-3211-TwoSAT,二分
- LA-3713-TwoSAT
- HDU-1814-TwoSAT
- POJ-3207-TwoSAT
- uva 11294 - Wedding(TwoSAT)
- UVALive 3211 Now or later 二分+Twosat
- BZOJ 1997: [Hnoi2010]Planar 平面图判定,TWOSAT
- uva 1086 - The Ministers' Major Mess(TwoSat)
- CF 776D The Door Problem TwoSAT 模板题
- fans-rt 介绍(4)-源码文件夹介绍
- OGC标准介绍 15
- 15、Jni介绍
- 博客介绍一下2017
- LeetCode064 Minimum Path Sum
- 多线程系列提高(4)--同步容器类
- 1006. 换个格式输出整数 (15)
- 线程同步工具之CountDownLatch
- 登山
- 2017/4/15 Twosat介绍
- github上传本地代码失败
- java中泛型有什么用,举例说明?
- LeetCode065 Valid Number
- 字符串或数组全排列的三种方法
- 二分查找的递归实现
- 求1/2
- LeetCode066 Plus One
- Android 各部布局