Click to open link
Test instructions: Chinese question.
Train of thought: do a few dance chain of the topic, the first feeling always thought to use the network flow to write, Ah yy A will be wrong, obediently with dance chain to write, for this topic we can all 1 as a column, and then the line is a small matrix, each line is a small matrix connection can be eliminated 1, But first you have to give all the 1 numbers, and then the template dance chain.
#include <vector> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < Iostream> #include <algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull;const int in f=0x3f3f3f3f;const ll Inf=0x3f3f3f3f3f3f3f3fll;const int Maxn=260;int L[MAXN*MAXN],R[MAXN*MAXN],U[MAXN*MAXN],D[MAXN *maxn];//nodes up and down four-way linked list int c[maxn*maxn],h[maxn],cnt[maxn],vis[maxn];//c column H row CNT list number of elements int n,m,id,fans;void init ( int ll) {for (int i=0;i<=ll;i++) {cnt[i]=0; U[i]=d[i]=i; L[i+1]=i; r[i]=i+1; } r[ll]=0;id=ll+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 (K<fans) fans=k; Return } for (int i=r[0];i;i=r[i]) if (mm>cnt[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 A[20][20],b[20][20];int Main () {int u,v,len,wid; while (scanf ("%d%d", &n,&m)!=-1) {int kk=0,kkk=1; for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) {scanf ("%d", &a[i][j]); if (a[i][j]==1) b[i][j]= (++KK); } scanf ("%d%d", &len,&wid); Init (KK); for (int i=1;i<=n-len+1;i++) {for (int. j=1;j<=m-wid+1;j++) {for (int k=0;k<len;k++) {f or (int l=0;l<wid;l++) {if (a[i+k][j+l]==1) Link (Kkk,b[i+k][j+l]); }} kkk++; }} fans=kkk-1; Dance (0); printf ("%d\n", fans); } return 0;}
Fzu 1686 dance chain repeatable overlay