HDU 3498 whosyourdaddy (可重复覆盖舞蹈链)

题意:

给出N个点,M个边构成图。每选取一个点都可以覆盖其相邻点,问要覆盖所有点最少选几个点

思路:
每个点都作为一个点集,进行爆搜覆盖,舞蹈链模板题。

代码:

#include 

using namespace std;

const int maxn=60;
int L[maxn*maxn],R[maxn*maxn],U[maxn*maxn],D[maxn*maxn];
int C[maxn*maxn],H[maxn],cnt[maxn],vis[maxn];
int n,m,id,fans;
vectorG[maxn];
void init(){
    for(int i=0;i<=n;i++){
        G[i].clear();
        G[i].push_back(i);
        cnt[i]=0;U[i]=D[i]=i;
        L[i+1]=i;R[i]=i+1;
    }
    R[n]=0;id=n+1;
    memset(H,-1,sizeof(H));
}
void Link(int r,int c){
    cnt[c]++;C[id]=c;
    U[id]=U[c];D[U[c]]=id;
    D[id]=c;U[c]=id;
    if(H[r]==-1) H[r]=L[id]=R[id]=id;
    else{
        L[id]=L[H[r]];R[L[H[r]]]=id;
        R[id]=H[r];L[H[r]]=id;
    }
    id++;
}
void Remove(int Size){
    for(int j=D[Size];j!=Size;j=D[j])
        L[R[j]]=L[j],R[L[j]]=R[j];
}
void Resume(int Size){
    for(int j=D[Size];j!=Size;j=D[j])
        L[R[j]]=R[L[j]]=j;
}
int h(){
    int sum=0;
    memset(vis,0,sizeof(vis));
    for(int i=R[0];i;i=R[i]){
        if(vis[i]) continue;
        sum++;
        for(int j=D[i];j!=i;j=D[j]){
            for(int k=R[j];k!=j;k=R[k])
                vis[C[k]]=1;
        }
    }
    return sum;
}
void Dance(int k){
    int mm=maxn,pos;
    if(k+h()>=fans)
        return;
    if(!R[0]){
        if(kcnt[i]){
            mm=cnt[i];
            pos=i;
        }
    for(int i=D[pos];i!=pos;i=D[i]){
        Remove(i);
        for(int j=R[i];j!=i;j=R[j])
            Remove(j);
        Dance(k+1);
        for(int j=R[i];j!=i;j=R[j])
            Resume(j);
        Resume(i);
    }
}
int main(){
    int u,v;
    while(scanf("%d%d",&n,&m)!=-1){
        init();
        for(int i=0;i

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.
InputThere 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. OutputOne 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


你可能感兴趣的:(—————数据结构—————,<<舞蹈链>>,可重复覆盖)