"BZOJ1226" school canteen dining (like pressure DP)

Source: Internet
Author: User
Tags cas

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&LT;&LT;L) =0  Then +           begin A            ifI+l>r ThenBreak ; theR:=min (r,i+b[i+l]+l); +dp[i,j+ (1&LT;&LT;L), L]:=min (dp[i,j+ (1&LT;&LT;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)

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.