Samsung ADV:Generating a Map Application(未AC)

Generating a Map Application

C/C++/JAVA 3S

The plan is to create a map-application which helps find the way from a starting point to a destination point through passing several stops.
The map is constructed of N lines in width and N lines in height (N*N), and given as a square shaped grid.
[Fig. 1] below is an example of a map with N=5.
在这里插入图片描述
[Fig. 1]

On the map, the points to stop at are marked with M numbers that are given from 1 to M.
⦁ 1: Starting point
⦁ 2~3: Stop point
⦁ 4: Destination point

In case of the map [Fig.1] above, the destination point number M is 4, the starting point 1 and the points to stop at sequentially are 2, 3 and the destination point is eventually point 4.

Also, there are areas on the map that are marked with在这里插入图片描述 .
This means that there has been an accident and thus cannot be passed.

Given are N, M- the size of the map, the destination point number- and the information on the map.
Write a program that finds the number of shortest paths form the starting point by passing each stop in number order to reach the destination point.
The paths must be the shortest distance. Print “0”, if no path exists.

[Example]
If a map as demonstrated above in [Fig.1] is given the number of shortest paths is as follows.
⦁ First, by starting with 1->2, there are 3 ways as demonstrated below in [Fig. 2]

在这里插入图片描述
⦁ Next, by moving form 2->3 there are 3 ways as demonstrated below in [Fig. 3].
在这里插入图片描述
⦁ Lastly, by moving form 3->4, there are 2 ways as demonstrated below in [Fig. 4].

在这里插入图片描述
Therefore, the number of total shortest paths is – multiplying each of 1), 2), 3) by their ways- which is 332=18.

{Constraints}
⦁ The size of the map N is given as an integer which is greater than or equal to 3 and less than or equal to 7(3<=N<=7)
⦁ The destination point number M is given as an integer which is greater than or equal to 2 and less than or equal to 5(2<=M<=5)
⦁ A case where the number of ways to be printed exceeds the int range will not be given in any case.
⦁ When searching a path between two points, it is possible to pass through other given points (the starting point, stops, destination point), as long as it is not passing an accident point.
([Fig. 5] below demonstrates an example of moving this way.)

在这里插入图片描述
[Fig. 5]

[Input]
The first line contains a single integer T- the number of total test case.
From the next line on each test case is given. The first line of each test case contains N, M in order – the size of the map, the destination point number.
On the following line, the N*N map size information is given. The numbers 1 to M on the map denote the starting point (1), the stops and the destination point (M). “9” refers to an accident point.

[In/Output Example]
Input Example
5
5 4
1 0 0 0 0
0 0 0 0 0
0 2 0 4 0
9 0 0 9 0
0 0 0 3 0
3 3
1 0 0
0 2 9
0 9 3
6 5
0 0 0 0 0 9
0 0 0 0 9 0
0 0 0 5 0 0
2 9 9 0 0 9
3 0 0 0 0 0
1 0 0 0 04
7 2
0 0 0 0 0 0 0
0 9 9 9 9 9 0
0 0 0 0 0 9 0
0 9 9 0 0 9 0
0 9 0 0 2 9 0
0 9 9 9 9 9 0
0 0 0 0 0 0 1
7 5
1 3 0 0 0 0 0
9 0 0 0 0 0 0
0 0 5 0 0 0 0
0 0 0 9 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 4
0 0 0 0 0

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值