#P4009. 汽车加油行驶问题

    ID: 2942 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论网络流O2优化最短路费用流网络流 24 题

汽车加油行驶问题

Description

Given an N×NN \times N square grid with the top-left corner as the start point ◎ at coordinates (1,1)(1, 1), where the XX-axis increases to the right and the YY-axis increases downward, and each grid cell has side length 11, as shown in the figure.

A car starts from ◎ and drives to the bottom-right corner ▲ at coordinates (N,N)(N, N).

Fuel depots are set at some grid intersections, where the car can refuel during the trip. The car must follow these rules:

  1. The car can move only along grid edges, and with a full tank it can travel KK grid edges. The car starts with a full tank. There are no depots at the start or end points.
  2. When the car traverses a grid edge, if its XX-coordinate or YY-coordinate decreases, it must pay a fee of BB; otherwise, there is no fee.
  3. When the car encounters a depot during the trip, it must refuel to full and pay a refueling cost of AA.
  4. When needed, a new depot may be added at a grid point by paying an installation cost of CC (this does not include the refueling cost AA).
  5. N,K,A,B,CN, K, A, B, C are all positive integers and satisfy the constraints 2N100,2K102 \leq N \leq 100, 2 \leq K \leq 10.

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 N,K,A,B,CN, K, A, B, C.

Starting from the second line, an N×NN \times N binary matrix is given, ending at line N+1N + 1, with NN values per row.

If the value at row ii, column jj is 11, it means a fuel depot is set at the grid intersection (i,j)(i, j); if it is 00, 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: 2N100,2K102 \leq N \leq 100, 2 \leq K \leq 10.

Translated by ChatGPT 5