Dynamic planning of Vijos1386 IOI2007 miner's Catering

Source: Internet
Author: User

It is not difficult to feel the ioi of the early years, also noip difficulty ... It seems to be getting harder now.

State is represented by DP[N][A1][B1][A2][B2]

n means handling to the top n diners

The first group of miners got a recent food with A1, said the A1 of the previous food with B1, the second group of miners with A2 and B2 said

The values for A and B range from [0,3],0 to no food, but one for three different foods.

The first dimension can optimize space with a scrolling array

1#include <cstdio>2#include <cstring>3#include <algorithm>4 5 Const intmaxn=100001;6 7 intdp[2][4][4][4][4];8 //none=0,bread=1,meat=2,fish=39 intN;Ten CharSEQ[MAXN]; One intS[MAXN]; A  -InlineintCodeCharx) - { the     Switch(x) -     { -      Case 'B':return 1; -      Case 'M':return 2; +      Case 'F':return 3; -     } +     return 0;//Unused A } at  - voidinput () - { -scanf"%d",&N); -scanf"%s", seq); -      for(intI=0; i<n;i++) s[i]=code (Seq[i]); in } -  toInlineintValintCurintLast1,intlast2) + { -     if(last2==0)return(CUR==LAST1)?1:2; the     Else if(CUR==LAST1)return(LAST1==LAST2)?1:2; *     Else return(Last1==last2 | | cur==last2)?2:3; $ }Panax Notoginseng  - intSolve () the { +memset (dp[0],0xe0,sizeof(dp[0])); Adp[0][s[0]][0][0][0]=dp[0][0][0][s[0]][0]=1; the      for(intI=1; i<n;i++) +     { -         int& v=S[i]; $memset (dp[1],0xe0,sizeof(dp[1])); $          for(inta1=0;a1<4; a1++) -         { -             if(!A1) {//b1=0 the                  for(intA2=1;a2<4; a2++) -                      for(intB2=0;b2<4; b2++) {Wuyidp[1][v][0][a2][b2]=Std::max the(dp[1][v][0][A2][B2], -dp[0][0][0][a2][b2]+1); Wudp[1][0][0][v][a2]=Std::max -(dp[1][0][0][V][A2], Aboutdp[0][0][0][a2][b2]+Val (v,a2,b2)); $                     } -             } -             Else  for(intb1=0;b1<4; b1++) -                  for(intA2=0;a2<4; a2++) A                 { +                     if(!A2) { thedp[1][a1][b1][v][0]=Std::max -(dp[1][a1][b1][v][0], $dp[0][a1][b1][0][0]+1); thedp[1][v][a1][0][0]=Std::max the(dp[1][v][a1][0][0], thedp[0][a1][b1][0][0]+Val (v,a1,b1)); the                     } -                     Else  for(intB2=0;b2<4; b2++) { indp[1][v][a1][a2][b2]=Std::max the(dp[1][V][A1][A2][B2], thedp[0][a1][b1][a2][b2]+Val (v,a1,b1)); Aboutdp[1][a1][b1][v][a2]=Std::max the(dp[1][A1][B1][V][A2], thedp[0][a1][b1][a2][b2]+Val (v,a2,b2)); the                     } +                 } -         } thememcpy (dp[0],dp[1],sizeof(dp[1]));Bayi     } the     intans=-1; the      for(inta1=0;a1<4; a1++) -          for(intb1=0;b1<4; b1++) -              for(intA2=0;a2<4; a2++) the                  for(intB2=0;b2<4; b2++) theAns=std::max (ans,dp[0][a1][b1][a2][b2]); the     returnans; the } -  the intMain () the { the input ();94printf"%d\n", Solve ()); the     return 0; the}

Dynamic planning of Vijos1386 IOI2007 miner's Catering

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.