Analysis:
DLX repeated coverage of the ingenious use, the principle of repeated coverage is exactly in line with the screening method, that is, select a number, the number of multiples or approximate can be guaranteed in the subsequent search will not be selected so modify the heuristic function, solve the largest repeat coverage. In fact, not necessarily not be selected, just choose later, either reach the goal, or achieve the goal, or not choose better than the following example 32 3 6 The answer is 2 the initial dancing links are said to be 2 3 62 1 0 13 0 1 16 1 1 1 then be sure to first select the first row to delete the first line. 2 3 62 0 0 03 0 1 06 0 1 0 This time either the second row is deleted or the third row is deleted, so 6 corresponds to the third row is optional, but the third line is selected, no effect on the answer
#include <cstdio>#include<cstring>#include<queue>#include<cstdlib>#include<algorithm>#include<vector>#include<cmath>using namespaceStd;typedefLong LongLL;Const intn=1e6+5;Const Doubleeps=1e-8;intn,m,sz,k;intU[n],l[n],r[n],d[n];inth[1005],s[1005],col[n];voidinit () { 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; SZ=m; for(intI=1; i<=n; ++i) h[i]=-1;}voidLinkintXinty) { ++sz; ++s[y],col[sz]=y; U[SZ]=u[y],d[u[y]]=sz; D[SZ]=y,u[y]=sz; if(h[x]==-1) h[x]=l[sz]=r[sz]=sz; {L[sz]=L[h[x]]; R[L[H[X] ]=sz; R[SZ]=H[x]; L[H[X]]=sz; }}voidDelinty) { for(intI=d[y]; I!=y; I=D[i]) r[l[i]=r[i],l[r[i]]=l[i];}voidResumeinty) { for(intI=d[y]; I!=y; I=D[i]) r[l[i]=l[r[i]]=i;}intf () {intret=0; for(inti=r[0];i;i=r[i]) + +ret; returnret;}intans;voidDanceintPOS) { if(Pos+f () <=ans)return; if(!r[0]) {ans=Max (Pos,ans); return; } intt=r[0]; for(inti=r[0]; i!=0; I=R[i])if(S[i]<s[t]) t=i; for(intI=D[T]; i!=t; I=D[i]) {del (i); for(intJ=r[i]; J!=i; j=R[j]) del (j); Dance (POS+1); for(intJ=l[i]; J!=i; j=L[j]) resume (j); Resume (i); }}ll a[1005];intMain () {intT; scanf ("%d",&T); while(t--) {scanf ("%d",&N); for(intI=1; i<=n;++i) scanf ("%i64d",&A[i]); Sort (a+1, A +1+N); M=N; Init (); for(intI=1; i<=n;++i) for(intj=1; j<=n;++j)if(a[i]%a[j]==0|| a[j]%a[i]==0) Link (i,j); Ans=0; Dance (0); printf ("%d\n", ans); } return 0;}
View Code
HDU 3335 divisibility dancing links repeat overwrite