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状态选到结束得 ...
随机推荐
- Ubuntu环境下手动配置ant
配置ant 1. 下载ant(http://ant.apache.org/bindownload.cgi) 例如我下载的是:apache-ant-1.9.4-bin.tar.gz 解压ant,将文件夹 ...
- Strust2最基本使用
制作一个登陆表单,然后在另一个页面显示提交的内容,简单的一个小工程. 页面: //login.jsp <form action="login.action" method=& ...
- hdu2015
http://acm.hdu.edu.cn/showproblem.php?pid=2015 #include<iostream> #include<stdio.h> #inc ...
- *[hackerrank]Sam and sub-strings
https://www.hackerrank.com/contests/w3/challenges/sam-and-substrings DP.注意到以N[i]结尾的每个字符串的子数字和有规律: 53 ...
- 254. Factor Combinations
题目: Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a ...
- IPC$命令详解
一 摘要二 什么是ipc$三 什么是空会话四 空会话可以做什么五 ipc$所使用的端口六 ipc管道在hack攻击中的意义七 ipc$连接失败的常见原因八 复制文件失败的原因九 关于at命令和xp对i ...
- Python第一天——初识Python
python是由荷兰人Guido van Rossum 于1989年发明的一种面向对象的的解释型计算机程序设语言,也可以称之为编程语言.例如java.php.c语言等都是编程语言. 那么为什么会有编程 ...
- 【原创】Sliding Window Maximum 解法分析
这道题是lintcode上的一道题,当然leetcode上同样有. 本题需要寻找O(N)复杂度的算法. 解体思路比较有特点,所以容易想到参考 最小栈 的解题办法. 但是最小栈用栈维护最小值很直观,这道 ...
- iOS处理XMl提供GDataXMLNode下载的链接
GDataXMLNode .好东西,处理xml 在iOS 中使用.可以编辑和读取Xml文档.支持Xpath.这个很好. GDataXMLNode.h GDataXMLNode.m 文件很不好找啊. / ...
- NDK(18)使用C++ STL
1,在Application.mk 中使用 APP_STL := stlport_static 等. APP_ABI := x86 armeabi APP_PLATFORM := android-15 ...