Fzu 1686 Dragon's puzzle DLX repeatedly covered

Source: Internet
Author: User


DLX repeatedly covered:

Need a A * function to cut the branch




problem 1686 The dragon's puzzleaccept:462 submit:1401
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, and the people live and live in peace, and there are less demons. But. There are always some magic things that come near the city, Disturb the lives of the people. Some people will come out to protect the inhabitants from the evil. Magic makes Emily the one. She rode on 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 hopes to complete the task with minimal damage. She used time to stop the magic stop time, and then he would make a fireball to burn the enemy. Myskgräs wanted to know how he would kill the enemy as quickly as he could 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 of the task. Then there are n rows, each with m integers, such as 1 to indicate that the point has a monster, and 0 to indicate that the point is free of monsters. Then the next line has two integers, N1,m1 (n1<=n,m1<=m), respectively, represents the row that Myskgräs can attack, the number of columns (the rows cannot be interchanged), If the Myskgräs can emit a fireball in a single unit of time, all monsters can be killed by a single blow.

Output

The
output line, an integer, represents the shortest time that the meter-drop destroys all the magic objects.

Sample INPUT4 0 0 1 1 1 1 Output41 0 0 4 0 0 0 1 1 1 1 0 0, 2 Sample sourcefoj Month-February 2009-Tim Eloop

pid=1686 "style=" text-decoration:none; Color:black ">submit back Status


#include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using namespace    std;const int maxn=250,maxm=250;const int maxnode=maxn*maxm;const int inf=0x3f3f3f3f;int n,m;int GA[20][20];struct DLX{    int n,m,size;    int U[maxnode],d[maxnode],r[maxnode],l[maxnode],row[maxnode],col[maxnode];    int H[maxnode],s[maxnode];    BOOL VIS[MAXM];    int ANSD;        void init (int _n,int _m) {ansd=inf; N=_n;        M=_m; for (int i=0;i<=m;i++) {s[i]=0;            U[i]=d[i]=i; L[i]=i-1;        r[i]=i+1; } r[m]=0;        L[0]=m;        Size=m;        for (int i=1;i<=n;i++) {h[i]=-1;        }} void Link (int r,int c) {++s[col[++size]=c];        Row[size]=r;        D[SIZE]=D[C];        U[d[c]]=size;        U[size]=c;        D[c]=size;        if (h[r]<0) h[r]=l[size]=r[size]=size;            else {r[size]=r[h[r]];            L[r[h[r]]]=size;         L[SIZE]=H[R];   R[h[r]]=size;    }} 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;        } int Astart () {int ret=0;        for (int i=r[0];i!=0;i=r[i]) vis[i]=true;                for (int c=r[0];c!=0;c=r[c]) {if (vis[c]==true) {ret++;                Vis[c]=false;            For (int. I=d[c];i!=c;i=d[i]) for (int j=r[i];j!=i;j=r[j]) Vis[col[j]]=false;    }} return ret;        } void Dance (int d) {if (D+astart () &GT;=ANSD) return;            if (r[0]==0) {///find ans;            Ansd=min (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);        }}};D lx Dlx;int main () {while (scanf ("%d%d", &n,&m)!=eof) {int gn=1;                for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) {scanf ("%d", &ga[i][j]);            if (ga[i][j]==1) ga[i][j]=gn++;        } int N1,m1;        scanf ("%d%d", &n1,&m1);        Attract point int ap= (n-n1+1) * (m-m1+1);        gn--;        Dlx.init (AP,GN); for (int i=1;i+n1-1<=n;i++) {for (int j=1;j+m1-1<=m;j++) {int nap= (i-1) *                (m-m1+1) +j;                         for (int ii=i;ii<=i+n1-1;ii++) {for (int jj=j;jj<=j+m1-1;jj++) { if (GA[II][JJ]) DLX.                    Link (NAP,GA[II][JJ]); }}}} DLX.        Dance (0); printf ("%d\n", DLX.ANSD); } return 0;}


Fzu 1686 Dragon's puzzle DLX repeatedly covered

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.