Namuk's Rotten Egg Tray
Time limit4sMemory limit512 MB
Place up to K nonoverlapping domino covers on an N by N tray to hide the most rottenness and report the remaining sum.
- Level
Medium7 of 10
- Topics
- Backtracking, Sorting, Matrix
- Solved
- No attempts yet
Problem
Namuk sells eggs in an egg tray. Every egg carries a rottenness value, and a larger value means a more rotten egg. While Namuk was busy with a new romance the eggs sat untouched and went bad, so he wants to hide the rotten ones under covers and bring the visible rottenness down.
The covers follow these rules.
- One cover hides two eggs that sit next to each other horizontally or vertically.
- Covers may not overlap. Touching is allowed.
- Namuk may place up to covers, and he does not have to use them all.
Place the covers so that the sum of the rottenness of the uncovered eggs is as small as possible, then report that sum.
Input
The first line has the tray size and the number of covers , separated by a space. (, )
Each of the next lines has the rottenness of eggs, separated by spaces. ()
Output
Print the smallest possible sum of the rottenness of the uncovered eggs on the first line.