4 Blocks
Time limit2sMemory limit512 MB
Fill the empty cells of a small N x M board with 1x1 and 2x2 blocks to maximize total score, given fixed 1x1 blocks.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
4 Blocks is a cooperative game that two people play on a board. The board is made of square cells. The game has two kinds of blocks: the '1' block and the '4' block. A '1' block is in size, and a '4' block is in size.
Blocks must be placed along the cell boundaries, and no two blocks may overlap. The final score is the sum of the numbers written on the cells. So a '1' block is worth 1 point, and a '4' block is worth 16 points in total, because a 4 is written on each of its four cells.
Hyobin has already placed some '1' blocks on the board. Now Youngsun wants to place '1' blocks and '4' blocks on the rest of the board to make the score as large as possible.

The left picture shows the board as Hyobin left it, and the right picture shows a placement with the maximum score. That score is .
Input
The first line contains the height and the width of the board. (, )
Each of the next lines contains a string of length describing the board Hyobin left. '.' is an empty cell, and '1' is a cell with a '1' block on it.
Output
Print the maximum score Youngsun can get on the first line.