problem 1686 The dragon's puzzleaccept:661 submit:1983
Time limit:1000 mSec Memory limit:32768 KB problem Description
It's a world of Swords and magic. Heroes and demons coexist, turbulent and stable. But all in all, the Kingdom of Kurt is a peaceful country, the people live and live in peace, and the magic is less. But there are always some magic things that come into the city, Disturb the lives of the people. Some people will come out to protect the residents from the evil. Magic makes Emily the one. She rode her mount, the Dragon Myskgräs together to destroy the demons that interfered with the survival of mankind and to maintain the stability of the kingdom. Emily wanted to be able to complete the task with minimal damage. She used time to stop the magic stop time, and then he could fire a fireball to burn the enemy. Myskgräs wants to know how he can kill the enemy as quickly as possible and relieve Emily's burden.
Input
There are several groups of data that you need to process to EOF. The first row of each group of data has two numbers, n,m, (1<=n,m<=15) represents the area range of the task. Then there are n rows, each M-integer, as 1 indicates that the point has a monster, 0 indicates that the point is free of monsters. Then the next line has two integers, N1,m1 (n1<=n,m1<=m), respectively, represents the line that Myskgräs once can attack, the number of columns (row and column can not be interchanged), assuming that a single unit of time to emit a fireball, all monsters can be a hit will kill.
Output
The
output line, an integer, represents the shortest time that the meter-drop destroys all the magic objects.
Sample Input4 41 0 0 10 1 1 00 1 1 01 0 0 12 24 40 0 0 00 1 1 00 1 1 00 0 0 02 2Sample Output41 sourcefoj Month-February 2009-Timeloop
Dancinglinksx repeated coverage of the topic
The topic meaning &
Practice
One Attack of Dragons as a line
Grid as Column
The dragon corresponds to an attack that can hit a position of 1.
Minimum number of times to ask for repeated overrides
It's a special place to get rid of the lattice without mobs.
That's a lot less columns.
#include <iostream> #include <stdio.h> #include <string.h>using namespace std;const int mn=20*20; const int Mm=20*20;const int mnn=mn*mm+mm; Maximum number of points struct dlx{int n,m,si;//n number of rows m column number of SI current node//cross list component int U[MNN],D[MNN],L[MNN],R[MNN],ROW[MNN],COL[MNN]; The first node of the U up Pointer D under L R right, where row row col int h[mn],s[mm]; Record row selection and column coverage int ANSD,ANS[MN]; void init (int _n,int _m)//Initialize empty table {n=_n; M=_m; for (int i=0;i<=m;i++)//Initialize First rampage (table header) {s[i]=0; U[i]=d[i]=i; The current longitudinal chain is empty l[i]=i-1; r[i]=i+1; Transverse to connect up} r[m]=0; L[0]=m; Si=m; Currently used the former 0~M node for (int i=1;i<=n;i++) h[i]=-1; } void link (int r,int c)//insertion point (R,C) {++s[col[++si]=c]; si++; Col[si]=c; s[c]++; Row[si]=r; D[SI]=D[C]; U[d[c]]=si; U[si]=c; D[c]=si; if (h[r]<0) H[r]=l[si]=r[si]=si; Else {R[si]=r[h[r]]; L[r[h[r]]]=si; L[SI]=H[R]; R[h[r]]=si; }} void remove (int c) {for (int i=d[c];i!= c;i= d[i]) l[r[i]]=l[i],r[l[i]]=r[i]; } void Resume (int c) {for (int i=u[c];i!= c;i=u[i]) l[r[i]]=r[l[i]]=i; } bool V[mnn]; int h ()//valuation {int ret=0; for (int c=r[0];c!=0;c=r[c]) v[c]=1; for (int c=r[0];c!=0;c=r[c]) if (V[c]) {ret++; v[c]=0; For (int. I=d[c];i!=c;i=d[i]) for (int j=r[i];j!=i;j=r[j]) v[col[j]]=0; } return ret; } void Dance (int d) {if (D+h () >=ANSD)//Use a * to optimize return; if (r[0]==0) {Ansd=d; Return } int c=r[0]; for (int i=r[0];i!=0;i=r[i]) if (s[i]<s[c]) c=i; for (int i=d[c];i!=c;i=d[i]) {Remove (i); for (int j=r[i];j!=i;j=r[j]) remove (j); Dance (d+1); for (int j = l[i];j! = I;j = L[j]) resume (j); Resume (i); }}}dlx;const int M=20;int ti[m][m];int p[m][m];int main () {int n,m,n1,m1; while (scanf ("%d%d", &n,&m)!=eof) {int pp=0; Remove the extra column for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) {scanf ("%d", &t I[I][J]); if (Ti[i][j]) p[i][j]=++pp; } scanf ("%d%d", &n1,&m1); Dlx.init ((n-n1+1) * (m-m1+1), pp); for (int ii=1;ii<=n-n1+1;ii++) for (int jj=1;jj<=m-m1+1;jj++) {int tmp= (ii-1) * (M -m1+1) +jj; for (int i=0;i<n1;i++) for (int j=0;j<m1;j++) if (Ti[ii+i][jj+j]) Dlx.link (Tmp,p[ii+i][jj+j]); } dlx.aNsd=1e9; Dlx.dance (0); printf ("%d\n", DLX.ANSD);//There must be a maximum number of times} return 0;}
Fzu_1686_ Dragon's Puzzle (DANCINGLINKSX repeat overlay)