Splitting the Pizza Tower (Small)
InterviewTime limit1sMemory limit512 MB
A tower of N pizzas is repeatedly split into two smaller towers, each split scoring the product of the two new heights. Find the maximum total score (N ≤ 10).
- Level
Easy3 of 10
- Topics
- Dynamic programming, Math, Greedy
- Solved
- No attempts yet
Problem

< Picture: Designed by Kstudio / Freepik >
Gap is a student at Ajou University. While preparing a department party on the first floor of Paldal Hall, he ordered pizzas. The delivered boxes sit on the table as a single tower. Gap has to break this tower of height into towers of height 1. He does not want to do it, but he remembers the line "if you can't avoid it, enjoy it" from Robert Eliot, so he turns the chore into the following game.
At the start of the game the table holds one tower of pizzas. Gap picks one tower from the table and splits it into two towers. If the two resulting towers have heights and , Gap feels pleasure from that split. A tower of height 1 is never split again. Gap repeats this until no tower on the table can be split, and at that moment his preparation is done.
You are given the number of pizzas that Gap ordered. Find the maximum total pleasure Gap can feel.

< Splitting a tower of height 8 into two towers of height 4 >
Input
The first line contains a positive integer (), the number of pizzas.
Output
Print the maximum total pleasure Gap can feel on one line.
Hint
When there is nothing to split from the start, so the total pleasure is 0.
Consider . Each () is one tower and the number inside is its height. The table starts with (3). Gap splits (3) into (1) and (2) and feels pleasure. He then splits the tower of height 2, leaving (1), (1), (1) on the table, and feels more. No tower can be split now, so the total is .