HDU 3498 DLX 重复覆盖

2014-11-24 08:50:46 · 作者: · 浏览: 0

whosyourdaddy

Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1197 Accepted Submission(s): 597


Problem Description sevenzero liked Warcraft very much, but he haven't practiced it for several years after being addicted to algorithms. Now, though he is playing with computer, he nearly losed and only his hero Pit Lord left. sevenzero is angry, he decided to cheat to turn defeat into victory. So he entered "whosyourdaddy", that let Pit Lord kill any hostile unit he damages immediately. As all Warcrafters know, Pit Lord masters a skill called Cleaving Attack and he can damage neighbour units of the unit he attacks. Pit Lord can choice a position to attack to avoid killing partial neighbour units sevenzero don't want to kill. Because sevenzero wants to win as soon as possible, he needs to know the minimum attack times to eliminate all the enemys.
Input There are several cases. For each case, first line contains two integer N (2 ≤ N ≤ 55) and M (0 ≤ M ≤ N*N),and N is the number of hostile units. Hostile units are numbered from 1 to N. For the subsequent M lines, each line contains two integers A and B, that means A and B are neighbor. Each unit has no more than 4 neighbor units. The input is terminated by EOF.
Output One line shows the minimum attack times for each case.
Sample Input
5 4
1 2
1 3
2 4
4 5
6 4
1 2
1 3
1 4
4 5

Sample Output
2
3


题意:给定n个点,m条联系,每一次攻击一个点可以同时攻击周边与他相邻的点,问最少攻击几个点,可以使得每一个点都被至少覆盖一次。

dlx重复覆盖问题,题目比较裸,直接建图,然后dlx+Astr。

代码:

/* ***********************************************
Author :xianxingwuguan
Created Time :2014-2-11 1:22:01
File Name :4.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         #include 
        
          #include 
         
           #include 
          
            #include 
           
             #include 
            
              #include 
             
               #include 
              
                #include 
                using namespace std; #define INF 0x3f3f3f3f #define eps 1e-8 #define pi acos(-1.0) typedef long long ll; const int maxn=10010; const int maxm=60; bool G[maxm][maxn]; int ans; struct DLX{ int L[maxn],R[maxn],U[maxn],D[maxn]; int size,col[maxn],S[maxn],H[maxn]; bool vis[maxm]; void init(int m){ for(int i=0;i<=m;i++){ L[i]=i-1; R[i]=i+1; U[i]=D[i]=i; S[i]=0; } memset(H,-1,sizeof(H)); L[0]=m;R[m]=0; size=m+1; } void del(int c){ for(int i=D[c];i!=c;i=D[i]){ L[R[i]]=L[i]; R[L[i]]=R[i]; } } void RR(int c) { int i; for(i=U[c];i!=c;i=U[i]) L[R[i]]=R[L[i]]=i; } void link(int r,int c){ U[size]=c; D[size]=D[c]; U[D[c]]=size; D[c]=size; if(H[r]<0)H[r]=L[size]=R[size]=size; else { L[size]=H[r]; R[size]=R[H[r]]; L[R[H[r]]]=size; R[H[r]]=size; } S[c]++;col[size++]=c; } int A(){ int i,j,k,res; memset(vis,0,sizeof(vis)); for(res=0,i=R[0];i;i=R[i]) if(!vis[i]){ res++; vis[i]=1; for(j=D[i];j!=i;j=D[j]) for(k=R[j];k!=j;k=R[k]) vis[col[k]]=1; } return res; } void dance(int now){ if(R[0]==0)ans=min(ans,now); else if(now+A()
                
                 S[i])temp=S[i],c=i; for(i=D[c];i!=c;i=D[i]){ del(i); for(j=R[i];j!=i;j=R[j])del(j); dance(now+1); for(j=L[i];j!=i;j=L[j])RR(j); RR(i); } } } }dlx; int main() { //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); int i,j,k,m,n,v,u; while(~scanf("%d%d",&n,&m)){ dlx.init(n); memset(G,0,sizeof(G)); while(m--){ scanf("%d%d",&u,&v); G[u][v]=G[v][u]=1; } for(i=1;i<=n;i++){ G[i][i]=1; for(j=1;j<=n;j++) if(G[i][j]) dlx.link(i,j); } ans=INF; // cout<<"hahha"<