Rokua P1133 The garden of the bishop

Source: Internet
Author: User

Title Description

The master has a circular garden where he wants to plant n trees evenly around the garden, but the soil of the master garden is very special, the trees are different for each location, and some trees may lose their ornamental value because they are unsuitable for the soil of this location.

The Archbishop likes 3 kinds of trees most, the height of these 3 kinds of trees is 10,20,30 respectively. The leader hopes that this circle of trees have a hierarchical sense, so any one location of the tree than it is adjacent to the height of the two trees are high or low, and in this condition, the leader wants you to design a plan, make the value of the highest ornamental.

Input/output format

Input format:

The 1th behavior of the input file garden.in a positive integer n that represents the tree of the tree to be planted.

The next n lines, each line 3 not more than 10000 positive integer ai,bi,ci, in a clockwise order, the first position of the height of the 10,20,30 tree can be obtained by the ornamental value.

The tree of the I position is adjacent to the tree in the i+1 position, in particular, the 1th position of the tree adjacent to the nth position of the tree.

Output format:

The output file Garden.out only includes a positive integer for maximum viewing value and.

Input and Output Sample input example # #:
4 1 3 2 3 1 2 3 1 2 3 1 2
Sample # # of output:
11
Description

"Sample description"

In the first place, the height of the 20,10,30,10 tree was planted in 1~n, which was the highest value.

"Data size and conventions"

For 20% of the data, there are n≤10;

For 40% of the data, there are n≤100;

For 60% of the data, there are n≤1000;

For 100% of the data, there is 4≤n≤100000, and ensure that n must be an even number.

One look is a DP problem. However, the position of 1 and n affects each other, resulting in the aftereffect of decision making.

Enumerate the trees in the 1 location (only three cases), DP, and take the maximum from the solution of three cases.

f[location [Tree of the location] [tree in the previous position]= maximum benefit

There are a lot of decision making methods, I choose violence to enumerate each decision. Specific look at the code

1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <vector>8 using namespacestd;9 Const intmxn=100010;Ten intRead () { One     intx=0, f=1;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -      while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} -     returnx*F; the } - intN; - intf[mxn][3][3];//length, end of two trees - inta[3][MXN]; + intans=0; - voidDP (intFirst) {//enumerate the first tree +Memset (F,0,sizeoff); A     inti,j; at      for(i=0;i<3; i++){ -         if(I==first)Continue; -f[2][i][first]=a[i][2]+a[first][1]; -     } -      for(i=3; i<=n;i++) {//Enumeration Location -          for(j=0;j<3; j + +) {//enumerate the kinds of trees on a previous location in             if(j==0){//The middle is the lowest tree, both sides need higher -                  for(intk=1; k<=2; k++) tof[i][k][0]=max (f[i-1][0][1],f[i-1][0][2])+A[k][i]; +                 Continue; -             } the             if(j==2){//The middle is the tallest tree, both sides need lower *                  for(intk=0; k<=1; k++) $f[i][k][2]=max (f[i-1][2][0],f[i-1][2][1])+A[k][i];Panax Notoginseng                 Continue; -             } the             if(j==1){//Middle is medium tree, both sides are either high or low +f[i][2][1]=f[i-1][1][2]+a[2][i]; Af[i][0][1]=f[i-1][1][0]+a[0][i]; the             } +         } -     } $     // $     Switch(first) {//according to the type of the 1th tree the type of the nth tree -          Case 0:{ -             inttmp=0; the              for(intk=1; k<=2; k++){ -                  for(intL=0; l<k;l++)Wuyitmp=Max (f[n][k][l],tmp); the             } -ans=Max (ans,tmp); Wu              Break; -         } About          Case 1:{ $             inttmp=0; -Tmp=max (f[n][2][1],f[n][2][0]); -Tmp=max (Tmp,max (f[n][0][1],f[n][0][2])); -ans=Max (ans,tmp); A              Break; +         } the          Case 2:{ -             inttmp=0; $              for(intk=0; k<=1; k++){ the                  for(intl=k+1; l<=2; l++) thetmp=Max (f[n][k][l],tmp); the             } theans=Max (Tmp,ans); -              Break; in         } the     } the      About } the intMain () { then=read (); the     inti,j; +      for(i=1; i<=n;i++){ -a[0][i]=read (); a[1][i]=read (); a[2][i]=read (); the     }Bayi      for(i=0;i<3; i++) DP (i); theprintf"%d\n", ans); the     return 0; -}

Rokua P1133 The garden of the bishop

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.