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

좋은 웹페이지 즐겨찾기