HDU 5765 Bonds 巧妙状压暴力
题意:给一个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 巧妙状压暴力的更多相关文章
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
- HDU 1045 Fire Net 状压暴力
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- hdu 5023 线段树+状压
http://acm.hdu.edu.cn/showproblem.php?pid=5023 在片段上着色,有两种操作,如下: 第一种:P a b c 把 a 片段至 b 片段的颜色都变为 c . 第 ...
- HDU 4281 Judges' response 状压dp+多旅行商问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4281 Judges' response Time Limit: 2000/1000 MS (Java ...
- hdu 3681(bfs+二分+状压dp判断)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
随机推荐
- Java学习笔记(二)UML基础
用例图:代表系统的一个功能模块,仅仅是系统功能的描述.用例图包括:用例.角色.角色和用例之间的关系以及系统内用例之间的关系. 类图:表示系统中包含哪些实体,各实体之间如何关联. 类图除了表示实体内部结 ...
- eclipse安装反编译插件
1. 进入http://jadclipse.sourceforge.net/wiki/index.php/Main_Page#Download 下载 net.sf.jadclipse ...
- 54. Spiral Matrix
题目: Given a matrix of m x n elements (m rows, ncolumns), return all elements of the matrix in spiral ...
- Servlet的response输出到页面时乱码的解决方法
package com.mhb; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servle ...
- 如何禁用 radio ,设置为只读,不能选定
如何禁用 radio ,设置为只读,不能选定 禁用 radio ,设置为只读,不能选定: <input name="gender" type="radio" ...
- Spring中的mappingResources和mappingDirectoryLocations
今天使用Spring+Hibernate进行事务管理,按照顺序也就是配置,DataSource,Sessionfactory,事务管理器以及拦截器. DateSource可以直接使用Hibernate ...
- Maven基本操作命令
1.mvn package 此命令包含一系列过程:validate-->compile-->test-->package Maven根据pom文件里packaging的配置,决定是生 ...
- 【转载】String、StringBuffer与StringBuilder之间区别
文章来源:http://www.cnblogs.com/A_ming/archive/2010/04/13/1711395.html 这两天在看Java编程的书,看到String的时候将之前没有弄懂的 ...
- 分享一个免费SSL证书申请网站,给网站开启https协议 | 张戈博客
这些天,由于公司的业务需求,接触到了ssl证书和https协议.博客前几篇文章也分享了在WEB服务器上安装SSL证书,为网站开启https协议的教程,感兴趣的童鞋可以前往查看相关文章: <Lin ...
- Uboot 2014.07 makefile分析 - 其他Cortex系列
uboot的官网可以通过谷歌搜索得到,显示结果第一个链接就是. 官网:: http://www.denx.de/wiki/U-Boot ftp下载: ftp://ftp.denx.de/pub/u-b ...