题意:给一个20个点无向连通图,求每条边被多少个极小割集包括

分析:极小割集是边的集合,很显然可以知道,极小割集恰好吧原图分成两部分(这个如果不明白可以用反证法)

然后就是奉上官方题解:http://bestcoder.hdu.edu.cn/blog/ 2016多校训练第4场1003

其实大体思路就是每次枚举一种可能的割集,即状压枚举,其中有不合法的,可以通过预处理标记所有的合法状态

剩下的就是贴代码了,好好看代码细节才是最重要的

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
const int N = (<<)+;
int g[N],sum[N],T,kase,n,m,u[],v[],tot;
bool can[N];
queue<int>q;
inline int lowbit(int x){return x&(-x);}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m),tot=<<n;
memset(g,,sizeof(g));
memset(can,false,sizeof(can));
memset(sum,,sizeof(sum));
for(int i=;i<m;++i){
scanf("%d%d",&u[i],&v[i]);
g[<<u[i]]|=<<v[i];
g[<<v[i]]|=<<u[i];
}
for(int i=;i<tot;++i)
g[i]|=g[i-lowbit(i)]|g[lowbit(i)];
for(int i=;i<n;++i)q.push(<<i),can[<<i]=true;
while(!q.empty()){
int u=q.front();q.pop();
int go=g[u]^(g[u]&u);
while(go){
int to=lowbit(go)|u;
if(!can[to])q.push(to),can[to]=true;
go-=lowbit(go);
}
}
int all=;
for(int i=;i<tot;++i){
int j=(tot-)^i;
if(i<j&&can[i]&&can[j]){
++sum[i];++sum[j];++all;
}
}
for(int j=;j<n;++j){
for(int i=tot-;i>;--i)
if(!(i&(<<j)))sum[i]+=sum[i^(<<j)];
}
printf("Case #%d:",++kase);
for(int i=;i<m;++i)
printf(" %d",all-sum[(<<u[i])|(<<v[i])]);
printf("\n");
}
return ;
}

HDU 5765 Bonds 巧妙状压暴力的更多相关文章

  1. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  2. HDU 1045 Fire Net 状压暴力

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)  ...

  3. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  4. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. HDU 3605 Escape(状压+最大流)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Sub ...

  6. hdu 5023 线段树+状压

    http://acm.hdu.edu.cn/showproblem.php?pid=5023 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c . 第 ...

  7. HDU 4281 Judges' response 状压dp+多旅行商问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4281 Judges' response Time Limit: 2000/1000 MS (Java ...

  8. hdu 3681(bfs+二分+状压dp判断)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...

  9. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

随机推荐

  1. [SQL Server系] -- 约束

    什么是约束? 约束(Constraint)是SQL Server中提供的 自动保存数据库完整性 的一种方法,定义了可输入表或表的列中的数据限制条件. SQL Server中共有5中约束 PRIMARY ...

  2. Spring整合Ibatis

    Spring整合Ibatis javaibatisspring 所需jar清单           ibatis-2.*.jar    *为任意版本,下同,ibatis工作包           sp ...

  3. hdu 1426 Sudoku Killer

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1426 #include<stdio.h> #include<math.h> #in ...

  4. P1024 外星人的密码数字

    P1024 外星人的密码数字 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述     XXXX年突然有外星人造访,但大家语言不通,不过科学家们经过研究发现外星 ...

  5. lintcode:子数组之和为0

    题目: 子数组之和 给定一个整数数组,找到和为零的子数组.你的代码应该返回满足要求的子数组的起始位置和结束位置 样例 给出[-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. 解 ...

  6. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...

  7. SpringMVC学习总结(一)——SpringMVC入门

    摘要: Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是使用请求 ...

  8. JavaScript中样式,方法 函数的应用

    JavaScript中一个字母都不能错,编写的时候他不报错,也不提示,只有在执行的时候才会提示错误位置 . 一.样式 .waring {background-color:yellow } .highl ...

  9. 用Telnet发送HTTP请求

    1. 进入cmd命令环境 2. 输入"telnet www.baidu.com 80" 3. 利用快捷键"Ctrl+](右中括号)"来打开本地回显功能 (注本阶 ...

  10. 第三章:推荐系统冷启动与CB

    3.1冷启动问题简介: 冷启动问题(cold start)主要分三类: •     用户冷启动 •     物品冷启动 •     系统冷启动 参考解决方案: •     推热门 •     利用用户 ...