Once You Shoot, You Cannot Stop
Time limit1sMemory limit128 MB
Given board dimensions and bead counts per color, arrange beads and clear groups to maximize the sum of squared group sizes.
- Level
Hard9 of 10
- Topics
- Combinatorics, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
You play a Chain Shot! style game (also known as SameGame, Jawbreaker, Bubble Shot, and so on) on a rectangular board.
Each cell of the board holds one colored bead. On each turn the player picks one group of same-colored beads connected horizontally and vertically. Every bead in the chosen group is removed from the board. Then any bead left floating falls straight down, and any column with no beads left is removed, so the columns on its sides move together.
The score for a turn is the square of the number of beads in the chosen group. For example, removing a group of size in the figure above scores points.
When every bead on the board is gone the game ends, and the final score is the sum of the scores from all turns.
A level blueprint consists of the board size and the number of beads of each color. Given a blueprint, find the maximum score obtainable over all boards that can be built from it and all ways of playing them.
Input
The first line contains the number of rows , the number of columns , and the number of colors (, ).
The second line contains positive integers; the -th integer is the number of beads of color . The beads count sums to .
Output
Print, as a single integer, the highest total score obtainable across every board that can be built from the blueprint and every way of playing it.
Hint
For a blueprint with bead counts , the maximum score is . Below, each color is removed as a single group for points.






