Pebbles
Time limit1sMemory limit128 MB
Place pebbles on an N by N board so no two touch even diagonally, maximizing the sum of covered cell values.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force, Implementation
- Solved
- No attempts yet
Problem
You have an unlimited supply of pebbles to place on an board, where . Every square holds a positive point value between and inclusive. For example, a board might look like this:
Place pebbles on the board subject to two rules:
- At most one pebble may sit on any single square.
- No two pebbles may occupy adjacent squares. Two squares are adjacent when they touch horizontally, vertically, or diagonally.
The board never wraps around, so squares at opposite ends of a row or column, and the two far corners, are not adjacent.
Your score is the sum of the point values of every square that holds a pebble. Maximize this score.
The input may contain several boards; report the best attainable score for each one.
Input
Each board is a block of lines, and every line lists space-separated point values (one per square). A blank line separates consecutive boards. Keep reading boards until the input ends.
Output
For each board, print a single integer on its own line: the maximum total score achievable by a valid pebble placement.