c ++ vehicle refueling problem

Vehicle refueling problem

Title Description

Given an N * N square grid, starting from the upper left corner which is set ◎, coordinates (1,1), X-axis is positive to the right, the Y axis is positive, each side length of a square. A car starting from the starting point towards the bottom right corner of the end ◎ ▲, its coordinates (N, N). At some point grid cross, set up depots for cars refuel in a moving way. The car is moving process should comply with the following rules:

(1) cars can travel along the mesh edge, the oil can be filled with the K mesh edge. When starting the car has been filled with oil at the start and end point of no depot.
(2) When the car through a mesh edge, if its X coordinate or Y coordinate decreases, the fees payable B, or toll-free use.
(3) In case of car depot in the process of moving you should fill up and pay for the fuel costs A.
(4) can be added when required at a grid point of the depot, and the depot to pay additional costs C (excluding fuel costs A).
(5) (1) to (4) in each of the number N, K, A, B, C are positive integers, and satisfy the constraint: 2 <= N <= 100,2 <= K <= 10.

Entry

The first row is N, the value of K, A, B, C of. From the second line is a 0-1 N * N matrix, each row of N values, to the end of the N + 1 row. J-th column of the i-th row of the matrix is ​​provided at a value of 1 indicates a depot at the grid intersection (i, j), represents the depot is not set to 0. Each row of adjacent two numbers separated by a space.

Export

The minimum cost output.

Sample input

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  

Sample Output

12

prompt

(none)

AC Code

(To be continued)

Guess you like

Origin www.cnblogs.com/LJA001162/p/11299957.html