题意:给一个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. [转] 软件定义网络(SDN) 的应运而生

    原文见51CTO:http://network.51cto.com/art/201103/251425.htm 2012的故事 2012年的某天,你跟往常一样起床,打开电脑,却发现无法登录到邮箱.无法 ...

  2. LeeCode 1-Two Sum

    Two Sum Total Accepted: 125096 Total Submissions: 705262 Question Solution Given an array of integer ...

  3. java如何得到GET和POST请求URL和参数列表

    转载:http://blog.csdn.net/yaerfeng/article/details/18942739 在servlet中GET请求可以通过HttpServletRequest的getRe ...

  4. avi 格式详解

    http://blog.csdn.net/becomly/article/details/6283004 http://blog.csdn.net/easecom/article/details/45 ...

  5. Java学习笔记之:Java StringBuffer类

    一.引言 当对字符串进行修改的时候,需要使用StringBuffer类. 和String类不同的是,StringBuffer和StringBuilder类的对象能够被多次的修改,并且不产生新的未用对象 ...

  6. javascript基础之数组对象

    一.定义数组的方法: 定义了一个空数组: var myArray =new Array(); 指定有n个空元素的数组: var myArray=new Array(n); 定义数组并赋值: var m ...

  7. sql server 读取表结构

    SELECT 表名 then d.name else '' end, 字段序号=a.colorder, 主键 FROM sysobjects where xtype='PK' and name in ...

  8. R语言字符串函数

    字符串长度: nchar("hello world") #字符串连接:paste) <- value substr("abcdef", 2, 4)[1] ...

  9. sscanf() 和 sprintf()的用法。

    因为感觉比较有用. 这几次比赛,用过几次,所以写个程序,总结一下. 如果用sscanf(s, "%d.%d", &a, &b); 的时候,一定要注意是否s里一定有小 ...

  10. 函数lock_rec_bitmap_reset

    /*********************************************************************//** Resets the record lock bi ...