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 = (1<<20)+5;
int g[N],sum[N],T,kase,n,m,u[205],v[205],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=1<<n;
    memset(g,0,sizeof(g));
    memset(can,false,sizeof(can));
    memset(sum,0,sizeof(sum));
    for(int i=0;i<m;++i){
      scanf("%d%d",&u[i],&v[i]);
      g[1<<u[i]]|=1<<v[i];
      g[1<<v[i]]|=1<<u[i];
    }
    for(int i=1;i<tot;++i)
      g[i]|=g[i-lowbit(i)]|g[lowbit(i)];
    for(int i=0;i<n;++i)q.push(1<<i),can[1<<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=0;
    for(int i=1;i<tot;++i){
      int j=(tot-1)^i;
      if(i<j&&can[i]&&can[j]){
        ++sum[i];++sum[j];++all;
      }
    }
    for(int j=0;j<n;++j){
      for(int i=tot-1;i>0;--i)
       if(!(i&(1<<j)))sum[i]+=sum[i^(1<<j)];
    }
    printf("Case #%d:",++kase);
    for(int i=0;i<m;++i)
     printf(" %d",all-sum[(1<<u[i])|(1<<v[i])]);
    printf("\n");
  }
  return 0;
}

时间: 2024-11-05 02:37:23

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

HDU 5765 Bonds(状压DP)

[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不同的连通块,对于每条边,求出两边的联通块的划分方案数,就是对于该点的答案. [代码] #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int n,m,T,Cas=1

HDU 1045 Fire Net 状压暴力

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8073    Accepted Submission(s): 4626 Problem Description Suppose that we have a squar

HDU 4924 Football Manager(状压DP)

题目连接 : http://acm.hdu.edu.cn/showproblem.php?pid=4924 题意 : n(<=20)个人选出11个人作为首发组成a-b-c阵容,每个人都有自己擅长的位置,并且每个人和其他人会有单向的厌恶和喜欢关系,每个人对于自己擅长的位置都有两个值CA和PA,有喜欢或者厌恶关系的两个人在一起也会影响整个首发的CA总值,要求选出一套阵容使得CA最大,或者CA一样的情况下PA最大. 思路 : 状压搞,dp[s]s的二进制表示20个人中选了那几个人,然后规定选进来的顺序

hdu 2825 aC自动机+状压dp

Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5640    Accepted Submission(s): 1785 Problem Description Liyuan lives in a old apartment. One day, he suddenly found that there

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

Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others)Total Submission(s): 2382    Accepted Submission(s): 750 Problem Description Great! Your new software is almost finished! The only thing left to

HDU 1074 Doing Homework(状压DP)

Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after the deadline, the teacher will r

[BestCoder Round #3] hdu 4909 String (状压,计数)

String Problem Description You hava a non-empty string which consists of lowercase English letters and may contain at most one '?'. Let's choose non-empty substring G from S (it can be G = S). A substring of a string is a continuous subsequence of th

HDU 4909 String 统计+状压

因为连续异或满足区间减法性质,所以可以状压之后用异或来判断是否为符合条件的单词并且存储次数 一开始用map,一直超时.虽然直接用开1<<26的数组内存存的下,但是memset的时间肯定会超,但是只要在每次循环之后把加过的值减掉就可以绕过memset了. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits>

HDU 4770 状压暴力枚举

Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1415    Accepted Submission(s): 412 Problem Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't