???Path Search with Constraints

Consider the i-jij plane shown in Fig. 1Fig.1. The discrete-points, or nodes, of interest in this plane are indexed by ordered pairs of positive integers as those points in the first quadrant of the Cartesian plane. The basic problem is to find the least-cost path through the grid, which begins at a designated original node, (1,1)(1,1), and ends at the designated terminal node, (I,J)(I,J). Let us define what we mean by a “path” through the grid. A path from node (s,t)(s,t) to node (u,v)(u,v) is an ordered set of nodes (i.e., index pairs) of the form:

(s,t),(i_{1},j_{1}),(i_{2},j_{2}),(i_{3},j_{3}),...(u,v)(s,t),(i1,j1),(i2,j2),(i3,j3),...(u,v), where the intermediate i_{k},j_{k}ik,jk’s are monotonic, this means that i_{k-1} \leq i_{k}ik1ik and j_{i-1} \leq j_{i}ji1ji.

Costs are assigned to the nodes in the plane. Let us define the notation d_{N}(i,j)dN(i,j) being the cost associated with node (i, j)(i,j), and D_{min}(i, j)Dmin(i,j) for the cost from (1, 1)(1,1) to (i, j)(i,j) over the best path. Local path constraints are used to restrict the local range of a path in the vicinity of a given node in the grid. In Fig. 2Fig.2, we show the type of local path constraints applied for this problem in terms of sets of predecessor points. The summary of this type of local path constraints, slope weights, and dynamic programming recursion formula are:

D_{min}(i, j)=min\begin{Bmatrix}D_{min}(i-2, j-1)+a[d_{N}(i-1, j)+d_{N}(i,j)]\\ D_{min}(i-1,j-1)+bd_N(i, j)\\ D_{min}(i-1, j-2)+a[d_{N}(i, j-1)+d_{N}(i,j)]\end{Bmatrix}Dmin(i,j)=minDmin(i2,j1)+a[dN(i1,j)+dN(i,j)]Dmin(i1,j1)+bdN(i,j)Dmin(i1,j2)+a[dN(i,j1)+dN(i,j)] And before start, the D_{min}(1,1) = D_{N}(1,1)Dmin(1,1)=DN(1,1).

Consider the problem of finding the best path with least cost through the (I, J)(I,J) grid of local costs. Assume that the path must begin at (1, 1)(1,1) and end at (I, J)(I,J). The type of local path constraints shown in Fig. 2Fig.2 is applied. You can assume that the least-cost path **being found is unique**. We guarantee that the II and JJ does not exceed 2020.

Fig. 1

Fig. 2

Input Format

Slope weights aabb, and costs associated with nodes in the grid. Contains J+2J+2 lines.

Line 11aa

Line 22bb

Line 33d_{N}(1,1)\ d_{N}(2,1)\ d_{N}(3,1)\ ... d_{N}(I,1)dN(1,1) dN(2,1) dN(3,1) ...dN(I,1)

Line 44d_{N}(1,2)\ d_{N}(2,2)\ d_{N}(3,2)\ ... d_{N}(I,2)dN(1,2) dN(2,2) dN(3,2) ...dN(I,2)

Line 55d_{N}(1,3)\ d_{N}(2,3)\ d_{N}(3,3)\ ... d_{N}(I,3)dN(1,3) dN(2,3) dN(3,3) ...dN(I,3)

......

Line J+1J+1:d_{N}(1,J-1)\ d_{N}(2,J-1)\ d_{N}(3,J-1)\ ... d_{N}(I,J-1)dN(1,J1) dN(2,J1) dN(3,J1) ...dN(I,J1)

Line J+2J+2d_{N}(1,J)\ d_{N}(2,J)\ d_{N}(3,J)\ ... d_{N}(I,J)dN(1,J) dN(2,J) dN(3,J) ...dN(I,J)

Output Format

The total cost WW of the best path, and the ordered set of nodes for the best path. Contains k+1k+1 lines.

Line 11WW

Line 22(1,1)(1,1)

Line 33(i,j)(i,j)

......

Line k+1k+1(I,J)(I,J)

Please accurate to 10^{-6}106 for floating number. And there is no space in the coordinates.

样例输入
0.5
1
1 1 3 3 3 3 3 3 3
1 1 1 1 2 2 1 2 2
2 1 2 2 1 3 1 1 1
2 2 2 1 2 2 2 3 3
3 2 3 1 1 1 2 3 3
3 2 3 2 2 2 3 3 3
样例输出
10.000000
(1,1)
(2,2)
(3,3)
(4,4)
(5,4)
(6,5)
(7,5)
(8,6)
(9,6)
题目来源

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值