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. ASP.NET Repeater 绑定 DropDownList Calendar 选择日期

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  2. 4816 江哥的dp题b

    4816 江哥的dp题b  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给出两个1-N的随机排列A,B.若 ...

  3. 完成卸载vs2010后再安装

    在安装好vs2010后,更改了驱动器号,造成vs工具不能使用,所以需要卸载vs2010 使用Microsoft Visual Studio 2010 Uninstall Utility来卸载vs201 ...

  4. QT 记事本小程序

    //mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <Q ...

  5. QT 对话框二

    QMessageBox类 information()函数,主要是提示功能,不需要用户选择 StandardButton QMessageBox::information ( QWidget *pare ...

  6. QT QDateTime类、QTimer类

    QDateTime类,头文件#include <QDateTime> 可以使用QDateTime类来获得系统时间.通过QDateTime::currentDateTime()来获取本地系统 ...

  7. caffe的python接口学习(3):训练模型(training)

    如果不进行可视化,只想得到一个最终的训练model, 那么代码非常简单,如下 : import caffe caffe.set_device(0) caffe.set_mode_gpu() solve ...

  8. 更好的逐帧动画函数 — requestAnimationFrame 简介

    本文将会简单讲讲 requestAnimationFrame 函数的用法,与 setTimeout/setInterval 的区别和联系,以及当标签页隐藏时 requestAnimationFrame ...

  9. socket.io简单说明及在线抽奖demo

    socket.io简单说明及在线抽奖demo socket.io 简介 Socket.IO可以实现实时双向的基于事件的通信. 它适用于各种平台,浏览器或设备,也同样注重可靠性和速度. socket.i ...

  10. [BZOJ2257][Jsoi2009]瓶子和燃料(数学)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2257 分析: 1.先考虑确定的瓶子下的最小体积是多少 ①假设只有两个瓶子v1,v2,易 ...