HDU 3498 whosyourdaddy 重复覆盖 DLX+A*
2015-05-15 15:51
337 查看
whosyourdaddy
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1495 Accepted Submission(s): 749
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
One line shows the minimum attack times for each case.
[align=left]Sample Input[/align]
5 4 1 2 1 3 2 4 4 5 6 4 1 2 1 3 1 4 4 5
[align=left]Sample Output[/align]
2 3
[align=left]Author[/align]
sevenzero
[align=left]Source[/align]
2010 ACM-ICPC Multi-University Training Contest(7)——Host
by HIT
深渊领主有一个技能,溅射(顺势斩 Cleaving Attack),当它把一个单位杀死的时候与该其直接相连的所有单位都要被杀死。
求最少攻击单位数。
并不记得深渊领主有溅射啊..再一看原来不是Dota..是War3啊...呵呵
双十字链表美如画w
/** Author: ☆·aosaki(*’(OO)’*) niconiconi★ **/ //#pragma comment(linker, "/STACK:1024000000,1024000000") //#include<bits/stdc++.h> #include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <algorithm> #include <functional> #include <cmath> #include <vector> #include <queue> #include <map> #include <set> #include <list> #include <stack> //#include <tuple> #define ALL(v) (v).begin(),(v).end() #define foreach(i,v) for (__typeof((v).begin())i=(v).begin();i!=(v).end();i++) #define SIZE(v) ((int)(v).size()) #define mem(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define lp(k,a) for(int k=1;k<=a;k++) #define lp0(k,a) for(int k=0;k<a;k++) #define lpn(k,n,a) for(int k=n;k<=a;k++) #define lpd(k,n,a) for(int k=n;k>=a;k--) #define sc(a) scanf("%d",&a) #define sc2(a,b) scanf("%d %d",&a,&b) #define lowbit(x) (x&(-x)) #define pi pair<int,int> #define vi vector<int> #define PI acos(-1.0) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define TT cout<<"*****"<<endl; #define TTT cout<<"********"<<endl; inline int gcd(int a,int b) { return a==0?b:gcd(b%a,a); } #define INF 1e6 #define eps 1e-8 #define mod 10007 #define MAX 10010 #define maxn 60 #define maxm 360 using namespace std; int n,m,th,ans; int U[maxm],R[maxm],D[maxm],L[maxm]; int s[maxn]; int in[maxm]; bool pos[maxn][maxn]; void init() { mem(U); mem(D); mem(L); mem(R); mem(s); mem(pos); th=0; ans=INF; } int link(int ll, int rr, int uu, int dd) { th++; L= ll; R = rr; U = uu; D = dd; L[rr] = R[ll] = D[uu] = U[dd] = th; return th; } void remove(int x) { for (int i = D[x]; i != x; i = D[i])R[L[i]] = R[i], L[R[i]] = L[i]; } void restore(int x) { for (int i = D[x]; i != x; i = D[i])R[L[i]] = i, L[R[i]] = i; } void input() { int b,c; while(m--) { sc2(b,c); pos[b][c]=1; pos[c][b]=1; } lp(i,n) pos[i][i]=1; lp(i,n) link(i-1,0,th+1,th+1); lp(i,n) { int last=0; lp(j,n) if(pos[i][j]) { s[j]++; if (last) last=link(last,R[last],U[j],j); else last=link(th+1,th+1,U[j],j); in =j; } } } int H() { int re=0; bool vis[maxn]={0}; for (int x=R[0];x;x=R[x]) if (!vis[x]) { re++; for (int i=D[x];i!=x;i=D[i]) for (int j=R[i];j!=i;j=R[j]) vis[in[j]]=1; } return re; } void dance(int step) { if(!R[0]) { ans=min(ans,step); return; } if (step+H()>=ans)return; //printf("%d\n", step); int mm=INF,x; for (int i=R[0];i;i=R[i]) if (s[i]<mm) { mm=s[i]; x=i; } for (int i=D[x];i!=x;i=D[i]) { remove(i); for(int j=R[i];j!=i;j=R[j]) remove(j); dance(step+1); for (int j=R[i];j!=i;j=R[j]) restore(j); restore(i); } } int main() { //freopen("in.txt","r",stdin); while (~sc2(n,m)) { init(); input(); dance(0); printf("%d\n",ans); } return 0; } 相关文章推荐
- HDU 3498 whosyourdaddy DLX重复覆盖
- hdu - 3498 - whosyourdaddy(重复覆盖DLX)
- [DLX重复覆盖] hdu 3498 whosyourdaddy
- 【HDU】3498 whosyourdaddy 重复覆盖入门题
- hdu 3498 whosyourdaddy(重复覆盖+估价函数剪枝)
- HDU 3498 whosyourdaddy (可重复覆盖舞蹈链)
- hdu 3498 whosyourdaddy (重复覆盖,DLX+迭代加深A*)
- HDU 3498 whosyourdaddy【Dancing Links重复覆盖】
- HDU 3498 whosyourdaddy(DLX+A*||多重覆盖)
- HDU 4398 whosyourdaddy 精确覆盖,允许重复覆盖
- HDU 3498 whosyourdaddy
- 【HDU】3498 whosyourdaddy
- hdu 3498 whosyourdaddy 重复覆盖+DLX 每次攻击i和i的所有邻居,最少攻击多少人才能杀死所有敌人
- hdu 3498(DLX 重复覆盖)
- hdu 3498 whosyourdaddy
- hdu3498 whosyourdaddy--可重复覆盖舞蹈链
- HDU 5046 Airport【DLX重复覆盖】
- [ACM] HDU 2295 Radar (二分+DLX 重复覆盖)
- HDU 2828 Lamp(DLX重复覆盖)
- hdu 3498 whosyourdaddy 重复覆盖