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状态选到结束得 ...
随机推荐
- 【Linux高频命令专题(22)】gzip
概述 减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅 ...
- 【mysql的设计与优化专题(6)】mysql索引攻略
所谓索引就是为特定的mysql字段进行一些特定的算法排序,比如二叉树的算法和哈希算法,哈希算法是通过建立特征值,然后根据特征值来快速查找,而用的最多,并且是mysql默认的就是二叉树算法 BTREE, ...
- asp.net中几个网页跳转的方法及区别
1:注意:Response.Redirect("a.html")是不能跳出框架.IFRAME的. 可以使用 Response.Write("<script Lang ...
- 2410中断中SRCPND和INTPND清零的疑问
2410中断中SRCPND和INTPND清零的疑问SRCPND是中断源引脚寄存器,某个位被置1表示相应的中断被触发,但我们知道在同一时刻内系统可以触发若干个中断,只要中断被触发了,SRCPND的相应位 ...
- React组件测试(模拟组件、函数和事件)
一.模拟组件 1.用到的工具 (1)browerify (2)jasmine-react-helpers (3)rewireify(依赖注入) (4)命令:browserify - t reactif ...
- 47. Permutations II
题目: Given a collection of numbers that might contain duplicates, return all possible unique permutat ...
- sudo
sudo的目的:为非根用户授予根用户的权限: 配置文件:/etc/sudoers visudo命令编辑修改/etc/sudoers配置文件 1.一般用户赋权设置: [root@localhost ~] ...
- .net 程序员成长路线图?
https://www.zhihu.com/question/25474641 得看赵四本, @赵劼 推荐的. CLR via C# .net Essentials C# in Depth Frame ...
- Android开发之获取系统版本号
获取系统版本号:获取当前系统的版本号: textView.setText("Product Model: " + android.os.Build.MODEL + ",& ...
- TCSRM 593 div2(1000)(dp)
Problem Statement The pony Rainbow Dash wants to choose her pet. There are N animals who want t ...