http://poj.org/problem?id=1419 (题目链接)

题意

  求一般图最大独立集。

Solution

  最大独立集=补图的最大团。

代码

// poj1419
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<queue>
#define LL long long
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=200;
int f[maxn][maxn],c[maxn][maxn],p[maxn],ans[maxn],mx[maxn];
int n,m,cnt; void Init() {
memset(f,1,sizeof(f));cnt=0;
for (int i=1;i<=n;i++) c[0][i]=1;
}
void record(int s) {
cnt=s;
for (int i=1;i<=s;i++) ans[i]=p[i];
}
void dfs(int fa,int x,int s) {
if (n-x+s<cnt || s+mx[x+1]<cnt) return; //cut
p[s]=x;
if (cnt<s) record(s);
for (int i=x+1;i<=n;i++) if (c[fa][i] && f[x][i]) c[x][i]=1;
for (int i=x+1;i<=n;i++) if (c[fa][i] && f[x][i]) dfs(x,i,s+1);
for (int i=x+1;i<=n;i++) c[x][i]=0;
}
int main() {
int T;scanf("%d",&T);
while (T--) {
scanf("%d%d",&n,&m);
Init();
for (int u,v,i=1;i<=m;i++) {
scanf("%d%d",&u,&v);
f[u][v]=f[v][u]=0;
}
for (int S=n;S>=1;S--) { //倒着搜索
dfs(0,S,1);
mx[S]=cnt; //记忆化一下
}
printf("%d\n",cnt);
for (int i=1;i<=cnt;i++) printf("%d ",ans[i]);
puts("");
}
return 0;
}

  

【poj1419】 Graph Coloring的更多相关文章

  1. 【arc073e】Ball Coloring(线段树,贪心)

    [arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...

  2. 【最大点独立集】【poj1419】【Graph Coloring】

    题意: 最多能选取多少点,没有边相连. 解法: 取反图,求最大团 代码: #include<cstdio> #include<cstring> #include<iost ...

  3. 【427】Graph 实现 以及 DFS & BFS

    目录: Graph 实现 二维数组实现 Linked List 实现 DFS:深度优先搜索 stack 实现 recursion 实现 BFS:广度优先搜索(queue) 其他应用 非连通图遍历 - ...

  4. 【XSY2469】graph 分治 并查集

    题目大意 给你一张\(n\)个点\(m\)条边的无向图,问删去每个点后,原图是不是二分图. \(n,m\leq 100000\) 题解 一个图是二分图\(\Longleftrightarrow\)该图 ...

  5. 【CF1027E】Inverse Coloring(DP)

    题意:给出一个n*n的矩阵,要求在每个位置涂上黑/白色, 要求满足:任意相邻的两行,其颜色要么完全相同,要么完全相反 任意相邻的两列,其颜色也要么相同要么完全相反 且这个矩形中,不存在任意一个大小大于 ...

  6. 【HDOJ6343】Graph Theory Homework(贪心)

    题意: 给定n个点,每个点有权值a[i],从A走到B的花费是下取整sqrt(a[i]-a[j]),求从1号点走到n号点的最小花费 1<=n,a[i]<=1e5 思路: #include&l ...

  7. 【HDU4034】Graph

    题目大意:给定一个图的最短路,求原图中至少存在多少条边. 题解:利用 Floyd 的性质,枚举边 d[i][j],若存在一个不是两端点的点,使得 d[i][j]=d[i][k]+d[k][j] 成立, ...

  8. 【leetcode】1034. Coloring A Border

    题目如下: Given a 2-dimensional grid of integers, each value in the grid represents the color of the gri ...

  9. 【LeetCode】图论 graph(共20题)

    [133]Clone Graph (2019年3月9日,复习) 给定一个图,返回它的深拷贝. 题解:dfs 或者 bfs 都可以 /* // Definition for a Node. class ...

随机推荐

  1. Firefox访问https出现 ssl_error_weak_server_ephemeral_dh_key错误

    一个自签名的内部网站当ff访问时出现以下错误 SSL received a weak ephemeral Diffie-Hellman key in Server Key Exchange hands ...

  2. DBA应用技巧:如何升级InnoDB Plugin

    DBA应用技巧:如何升级InnoDB Plugin 2011-03-23 10:09 康凯 ITPUB 字号:T | T 本文中,我们将向读者详细介绍如何升级动态InnoDB Plugin和升级静态编 ...

  3. GridView EmptyDataTemplate 动态显示

    以下语句加在GridView.DataBind()之后: Table GridViewTable = ((Table)gvGridView.Controls[]); if (!isSearch) (( ...

  4. BZOJ 2301 【HAOI2011】 Problem b

    Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...

  5. [转]使用URLDecoder和URLEncoder对中文进行处理

    一 URLEncoder HTML 格式编码的实用工具类.该类包含了将 String 转换为 application/x-www-form-urlencoded MIME 格式的静态方法.有关 HTM ...

  6. 2015-2016-2 《Java程序设计》教学进程

    2015-2016-2 <Java程序设计>教学进程 目录 考核方式 寒假准备 教学进程 第00周学习任务和要求 第01周学习任务和要求 第02周学习任务和要求 第03周学习任务和要求 第 ...

  7. 在线音乐网站【04】Part two 功能实现

       上一篇博客里面已近总结了三个功能的具体实现,今天把剩余功能的具体实现补充总结,如果你想对整个小项目有清楚的了解,建议去看下前几篇博客. 1.在线音乐网站(1)需求和功能结构 2.在线音乐网站(2 ...

  8. opencv7-ml之svm

    因为<opencv_tutorial>这部分只有两个例子,就先暂时介绍两个例子好了,在refman中ml板块有:统计模型.普通的贝叶斯分类器.KNN.SVM.决策树.boosting.随机 ...

  9. location.href 实现点击下载功能

    如果页面上要实现一个点击下载的功能,传统做法是使用一个 a 标签,然后将该标签的 href 属性地址指向下载文件在服务端的地址(相对地址或者绝对地址),比如这样: 能这样实现是因为,在浏览器地址栏输入 ...

  10. python动态网页爬取——四六级成绩批量爬取

    需求: 四六级成绩查询网站我所知道的有两个:学信网(http://www.chsi.com.cn/cet/)和99宿舍(http://cet.99sushe.com/),这两个网站采用的都是动态网页. ...