#P3866. [TJOI2009] 战争游戏
[TJOI2009] 战争游戏
Description
Before the enemies start moving, your task is to use airstrikes to turn some originally empty cells into impassable cells, which may prevent the enemies from leaving the map. For special reasons, you cannot bomb any cell currently occupied by an enemy unit. Due to terrain differences, the amount of explosives needed to bomb each empty cell into an impassable cell may vary. You need to compute the minimum total amount of explosives required to prevent the enemies from moving out of the map boundary.
Input Format
The first line contains two integers and , the numbers of rows and columns of the grid. The next lines each contain space-separated integers, describing the grid cells:
- If the number is , the cell is an obstacle.
- If the number is , there is an enemy unit in this cell.
- If the number is a positive integer , the cell is empty, and units of explosives are needed to bomb it into an impassable cell.
The number of enemy units on the map is not equal to (i.e., there are at least two cells with ).
Output Format
Output a single number: the minimum total amount of explosives required. The testdata guarantee that a solution exists.
4 3
1 2 1
1 10 1
1 0 -1
1 1 1
6
Hint
- For 50% of the testdata, .
- For 100% of the testdata, .
- Every number in the matrix does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号