#1037: Digital Triangle time limit:10000msSingle Point time limit:1000msMemory Limit:256MB
Problem description
Little Hi and Little Ho were rewarded with a chance to travel abroad after experiencing Mr. Crab's task, so they came to America on the other side of the ocean. The life of the American people is very interesting, often there are all kinds of strange and strange activities held, this no, small hi and small ho just off the plane, caught up with the local maze festival activities. Maze Festival in the exhibition of the maze are particularly interesting, but small ho is actually not how much like a maze of maze-because this maze of reward is very rich ~
So small ho found a small hi, let small hi help him to get as many prizes, small hi hand one stretch way: "The introduction of the Maze to get!" ”
The maze chosen by Little Ho is a labyrinth of N (n not more than 200) known as the "number Triangle", and the first layer of the maze has I rooms numbered 1. I In addition to the last room, each room will have some stairs to the next floor of the room, with the symbol, that is, from the first floor of the room numbered J, there will be two roads, a room numbered J to the I+1 layer, the other will lead to the i+1 layer numbered j+1 room, And all the rooms on the last floor have only one way out of the maze. Such roads are one-way, which means that little ho will not be able to return to the room again when they go down the road to the next room or leave the maze. There will be only one participant in the maze, and a certain number of lotteries will be generated in each room when each participant enters the maze, which can be redeemed for various prizes after passing through the maze. Small Ho's starting point on the 1th floor of the room numbered 1, and now small ho quietly to other participants to find out the number of lottery tickets in each room, hoping that little hi to help him calculate the maximum number of tickets he can get.
Tip One: Blind greed is not advisable, search calculation is too time-consuming
Hint Two: Memory deep search for divinity, Width priority solution puzzle
Tip three: summed up the formula to reduce redundancy is the truth
Input
Each test point (input file) has and has only one set of test data.
The first behavior of each set of test data is a positive integer n, which represents the number of layers in the maze.
The next n lines describe the number of lotteries in each room in the maze, where the number of J on line I represents the amount of lottery tickets in the room numbered J of the maze layer I.
Test data assurance that 100% of the data satisfies n not more than 100
For 100% of the data, the number of layers N of the maze is not more than 100
For 100% of the data, the number of lotteries in each room does not exceed 1000
For 50% of the data, the number of layers in the maze is not more than 15 (small ho means that 2^15 is more than 30,000, which means ...). )
For 10% of the data, the number of layers in the maze is not more than 1 (little hi is curious about how your boundary situation is handled?). ~
For 10% of the data, the maze is constructed to satisfy: For more than 90% of the nodes, the left road leads to the number of lottery tickets in the room to the right road leading to the number of lottery tickets.
For 10% of the data, the maze is constructed to satisfy: For more than 90% of the nodes, the left road leads to a room with fewer lotteries than the right road leads to the room.
Output
For each set of test data, output an integer ans, which indicates the maximum number of lotteries that small ho can obtain.
-
-
Sample input
-
-
526 41 2 84 0 9 66 5 5 3 6
-
-
Sample output
-
-
28