您的位置:首页 > 其它

SOJ 1321. Robot

2013-08-24 21:43 309 查看

1321. Robot

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Karell Incorporated has designed a new exploration robot that has the ability to explore new terrains, this new robot can move in all kinds of terrain, it only needs more fuel to move in rough terrains, and less fuel in plain terrains. The only problem thisrobot has is that it can only move orthogonally, the robot can only move to the grids that are at the North, East, South or West of its position.The Karell`s robot can communicate to a satellite dish to have a picture of the terrain that is going to explore, so it can select the best route to the ending point, The robot always choose the path that needs the minimum fuel to complete its exploration,however the scientist that are experimenting with the robot, need a program that computes the path that would need the minimum amount of fuel. The maximum amount of fuel that the robot can handle is 9999 unitsThe Terrain that the robot receives from the satellite is divided into a grid, where each cell of the grid is assigned to the amount of fuel the robot would need to pass thought that cell. The robot also receives the starting and ending coordinates of the explorationarea.Path ExampleFrom (1,1) to (5,5)Fuel needed 10

Input

The first line of the input file is the number of tests that must be examined.The first line of the test is the number of rows and columns that the grid will contain. The rows and columns will be 0 < row100 , 0< column100The next lines are the data of the terrain gridThe last line of the test has the starting and ending coordinates.

Output

One line, for each test will have the amount of fuel needed by the robot

Sample Input

3
5 5
1 1 5 3 2
4 1 4 2 6
3 1 1 3 3
5 2 3 1 2
2 1 1 1 1
1 1 5 5
5 4
2 2 15 1
5 1 15 1
5 3 10 1
5 2 1 1
8 13 2 15
1 1 1 4
10 10
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 10 10

Sample Output

10
15
19

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Robot soj dijkstra