一个新手遇到的问题,希望高人能指点一下
Problem G
Grid Path
You have a grid, with each square filled with a one-digit number (0~9).
You can start from any square, walk up, down, left or right several times, concatenate every digit you encountered in the order you visit them, then remove leading zeros to obtain an integer.
Each time you can only goto a neighboring square inside the grid(sharing one edge with your current square), and you can move exactly s steps (including moving to the first square).
Each square can be accessed more than once and each time you visit it, the digit on the square is appended to your current path.
You should find the smallest number you can get, which is a multiple of k. You should also count the number of ways you can get it.
Two paths are different if they have different starting squares, or their move sequences are different.
Input
The first line contains a single integer T(1<=T<=50), the number of test cases.
Each test case begins with a line containing four integer: r,c,s,k(1<=r,c<=10,1<=s<=50,1<=k<=20), the number of rows, columns of the grid, the number of steps you should take, and the number described in the problem description.
The following r lines describes the grid. Each line contains exactly c columns.
Output
For each test case, print the case number and two integers: the smallest integer you can get, and the number of ways you can get it (gauranteed less than 1018).
If no solution is found, output -1 -1.
Sample Input
3
2 2 3 3
1 1
1 1
2 2 50 2
1 1
1 1
2 2 4 11
1 2
3 4
Sample Output
Case 1: 111 16
Case 2: -1 -1
Case 3: 1243 1
[解决办法]
这是考大家英语呢?
[解决办法]
Data Structure?
[解决办法]
搞不清楚咧