Fzu 1686 (Repeat overlay)

Source: Internet
Author: User

Topic Connection: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31370

Test instructions: Cover all the 1 in the large rectangle n*m with a small rectangle as little as possible, convert all 1 to a size column, and then make a row with 1 of each point of the large rectangle as the upper-left corner of the small rectangle r*c, and the problem is converted to a m*n row to overwrite all the columns with as few rows as possible ...

#include <cstdio>#include<cstring>#include<string>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<stack>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 10007#defineINF 0x3f3f3f3f#defineN 100010#defineFILL (A, B) (Memset (A,b,sizeof (a)))#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1using namespacestd;Const intMaxnode=250010;Const intmaxn=510;Const intmaxm=510;structdlx{intn,m,size; intU[maxnode],d[maxnode],r[maxnode],l[maxnode],row[maxnode],col[maxnode]; intH[MAXN],S[MAXM]; intANSD,ANS[MAXN]; voidInitint_n,int_m) {N=_n;m=_m;  for(intI=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(intI=1; i<=n;i++) h[i]=-1; }    voidLink (intRintc) {++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; }    }   voidRemove (intc) { for(inti = d[c];i! = C;i =D[i]) L[r[i]]= L[i], r[l[i]] =R[i]; }    voidResume (intc) { for(inti = u[c];i! = C;i =U[i]) L[r[i]]=r[l[i]]=i; }    BOOLVis[maxnode]; inth () {intres=0;  for(intc=r[0];c!=0; C=r[c]) vis[c]=true;  for(intc=r[0];c!=0; c=R[c])if(Vis[c]) {res++; VIS[C]=false;  for(intI=d[c];i!=c;i=D[i]) for(intj=r[i];j!=i;j=R[j]) vis[col[j]=false; }        returnRes; }    voidDance (intD//d is recursive depth    {        if(D+h () &GT;=ANSD)return; if(r[0]==0)//Find the solution        {            if(D&LT;ANSD) ansd=D; return; }        //find the smallest C column in S        intc=r[0];//first non-deleted column         for(inti=r[0];i!=0; i=R[i])if(S[i]<s[c]) c=i;  for(intI=d[c];i!=c;i=d[i])//Overwrite column C with the row where node I is located{Remove (i);  for(intJ=R[I];J!=I;J=R[J]) Remove (j);//Delete node I row overrides column CDance (d+1);  for(intJ=L[I];J!=I;J=L[J]) Resume (j);//RecoveryResume (i); }}};D lx G;intid[ -][ -];intMain () {intN,m,x,c,r;  while(SCANF ("%d%d", &n,&m) >0)    {        intsz=0;  for(intI=1; i<=n;i++)         for(intj=1; j<=m;j++) {scanf ("%d",&x); ID[I][J]=x?++sz:0; } g.init (n*M,sz); scanf ("%d%d",&r,&c);  for(intI=1, num=1; i<=n;i++)         for(intj=1; j<=m;j++,num++)        {             for(intx=0; x+i<=n&&x<r;x++)                 for(inty=0; y+j<=m&&y<c;y++)                if(id[i+x][y+j]) G.link (num,id[i+x][j+y]); } G.ANSD=n*L; G.dance (0); printf ("%d\n", G.ANSD); }}
View Code

Fzu 1686 (Repeat overlay)

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.