Test instructions: See surface
Idea: Set Dp[i,sta,k] for the former I person has eaten, from the first I to the i+b[i] people's eating status is STA, the last person to eat the distance from I is k (may be negative) the minimum value
\[dp[i+1,sta>>1,k-1]=min (Dp[i+1,sta>>1,k-1],dp[i,sta,k]) (STA and 1=1, if I have eaten) \]
\[dp[i,sta+1<<l,l]=min (Dp[i,sta+1<<l,l],dp[i,sta,k]+w (i+k,i+l) (I+l) (the first person to eat is i+k)
\[w (I,J) =b[i] or b[j]-b[i] and B[j]=b[i] XOR b[j]\]
Notice when the border is shifted, whether it exceeds the minimum tolerance within the L person
1 Constoo=2000000000;2 varDp:Array[1..1100,0.. -,-8..8] ofLongint;3T,b:Array[1..1100] ofLongint;4 Cas,v,n,i,j,k,l,ans,r:longint;5 6 functionClac (x,y:longint): Longint;7 begin8 ifx=0 ThenExit0);9 exit (T[x] XOR t[y]);Ten End; One A functionmin (x,y:longint): Longint; - begin - ifX<y Thenexit (x); the exit (y); - End; - - begin +Assign (input,'bzoj1226.in'); Reset (input); -Assign (output,'Bzoj1226.out'); Rewrite (output); + Readln (CAS); A forv:=1 toCas Do at begin - read (n); - fori:=1 toN Doread (t[i],b[i]); - Fillchar (Dp,sizeof (DP), $7f); -dp[1,0,-1]:=0; - fori:=1 toN Do in forj:=0 to(1<<8)-1 Do - fork:=-8 to 7 Do to ifDp[i,j,k]<oo Then + begin - ifJ and 1>0 Then thedp[i+1,j>>1, K-1]:=min (dp[i+1,j>>1, K-1],dp[i,j,k]) * Else $ beginPanax Notoginsengr:=Oo; - forl:=0 to 7 Do the ifJ and(1<<L) =0 Then + begin A ifI+l>r ThenBreak ; theR:=min (r,i+b[i+l]+l); +dp[i,j+ (1<<L), L]:=min (dp[i,j+ (1<<L), L],dp[i,j,k]+clac (i+k,i+l)); - End; $ End; $ End; -ans:=Oo; - fori:=-8 to-1 DoAns:=min (ans,dp[n+1,0, I]); the writeln (ans); - End;Wuyi close (input); the close (output); - End.
"BZOJ1226" school canteen dining (like pressure DP)