#P1133. 教主的花园
教主的花园
Description
The leader has a circular garden and wants to plant trees evenly around it. However, the soil is special; each position suits different kinds of trees, and some trees may lose aesthetic value if placed in unsuitable soil.
The leader's three favorite kinds of trees have heights . He wants the ring of trees to have a sense of layering: at every position, the tree must be strictly higher than both of its adjacent trees or strictly lower than both. Under this condition, design a plan that maximizes the sum of aesthetic values.
Input Format
The first line contains a positive integer , the number of trees to plant.
The next lines each contain three positive integers not exceeding , giving, in clockwise order, the aesthetic value obtained by planting at position a tree of height , respectively.
The tree at position is adjacent to the tree at position ; in particular, the tree at position is adjacent to the tree at position .
Output Format
Output a single positive integer, the maximum total aesthetic value.
4
1 3 2
3 1 2
3 1 2
3 1 2
11
Hint
[Sample Explanation].
Plant trees of heights at positions through , respectively, to achieve the highest value.
[Constraints].
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , and is guaranteed to be even.
Translated by ChatGPT 5
京公网安备 11011102002149号