#P4009. 汽车加油行驶问题
汽车加油行驶问题
Description
Given an square grid with the top-left corner as the start point ◎ at coordinates , where the -axis increases to the right and the -axis increases downward, and each grid cell has side length , as shown in the figure.

A car starts from ◎ and drives to the bottom-right corner ▲ at coordinates .
Fuel depots are set at some grid intersections, where the car can refuel during the trip. The car must follow these rules:
- The car can move only along grid edges, and with a full tank it can travel grid edges. The car starts with a full tank. There are no depots at the start or end points.
- When the car traverses a grid edge, if its -coordinate or -coordinate decreases, it must pay a fee of ; otherwise, there is no fee.
- When the car encounters a depot during the trip, it must refuel to full and pay a refueling cost of .
- When needed, a new depot may be added at a grid point by paying an installation cost of (this does not include the refueling cost ).
- are all positive integers and satisfy the constraints .
Design an algorithm to compute the minimum total cost for the car to travel from the start to the destination.
Input Format
The first line contains the values of .
Starting from the second line, an binary matrix is given, ending at line , with values per row.
If the value at row , column is , it means a fuel depot is set at the grid intersection ; if it is , no depot is set there. Adjacent numbers in the same row are separated by spaces.
Output Format
Output the minimum total cost at the end of the program.
9 3 2 3 6
0 0 0 0 1 0 0 0 0
0 0 0 1 0 1 1 0 0
1 0 1 0 0 0 0 1 0
0 0 0 0 0 1 0 0 1
1 0 0 1 0 0 1 0 0
0 1 0 0 0 0 0 1 0
0 0 0 0 1 0 0 0 1
1 0 0 1 0 0 0 1 0
0 1 0 0 0 0 0 0 0
12
Hint
Constraints: .
Translated by ChatGPT 5
京公网安备 11011102002149号