1133 The garden of the bishop of Los Valleys

Source: Internet
Author: User

1133 The garden of the bishop of Los Valleys

Address: http://www.luogu.org/problem/show?pid=1133

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/Output sample

Input Sample # #:

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.

Ideas

Ring DP.

If the garden is not a ring but a straight line: the definition of d[i][j] represents the maximum value of J for the first tree and the current state of the I tree. Then there is the transfer equation (see Code). Using someone else's technique can define j==2 's Chicho 20 and the trees on either side are shorter than him, the tree is 20 tall when defined j==3 and the trees on both sides are taller than him. This is not what I thought of.

For rings: Enumerates the height of the first tree, DP. Finally, only the enumeration-compliant d is examined.

Code

1#include <iostream>2#include <cstring>3 using namespacestd;4 5 Const intMAXN =1000000+Ten;6 Const intinf=1<< -;7 Const inth[]={0,1,2,2,3};8 intd[maxn][5],w[maxn][4];9 intN;Ten  One intMain () { AIos::sync_with_stdio (false); -Cin>>N; -      for(intI=1; i<=n;i++) cin>>w[i][1]>>w[i][2]>>w[i][3]; the      -     intans=-INF; -      for(intd1=1;d 1<=4;d 1++) { -memset (D,0,sizeof(d)); +          for(intI=1; i<=4; i++) d[1][i]=-inf;//indicates unreachable -d[1][D1] = w[1][h[d1]]; +          for(intI=2; i<=n;i++) A         { atd[i][1]=max (d[i-1][4],d[i-1][2]) +w[i][1]; -d[i][2]=d[i-1][1]+w[i][2]; -d[i][3]=d[i-1][4]+w[i][2]; -d[i][4]=max (d[i-1][1],d[i-1][3]) +w[i][3]; -         } -         Switch(d1) { in               Case 1: Ans=max (ans,d[n][2]); Ans=max (ans,d[n][4]); Break; -               Case 2: Ans=max (ans,d[n][1]); Break; to               Case 3: Ans=max (ans,d[n][4]); Break; +               Case 4: Ans=max (ans,d[n][1]); Ans=max (ans,d[n][3]); Break; -         } the     } *cout<<ans; $     return 0;Panax Notoginseng}

1133 The garden of the bishop of Los Valleys

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.