#P16490. [GKS 2014 #D] Cube IV

    ID: 16475 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>动态规划 DP2014Google Kick Start

[GKS 2014 #D] Cube IV

题目描述

Vincenzo decides to make cube IV but only has the budget to make a square maze. Its a perfect maze, every room is in the form of a square and there are 44 doors (11 on each side of the room). There is a big number written in the room. A person can only move from one room to another if the number in the next room is larger than the number in his current room by 11. Now, Vincenzo assigns unique numbers to all the rooms (11, 22, 33, .... S2S^2) and then places S2S^2 people in the maze, 11 in each room where S is the side length of the maze. The person who can move maximum number of times will win. Figure out who will emerge as the winner and the number of rooms he will be able to move.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of SS which is the side length of the square maze. Then S2S^2 numbers follow like a maze to give the numbers that have been assigned to the rooms.

11 22 99

55 33 88

44 66 77

输出格式

For each test case, output one line containing "Case #x: r d", where xx is the test case number (starting from 11), rr is the room number of the person who will win and dd is the number of rooms he could move. In case there are multiple such people, the person who is in the smallest room will win.

2
2
3 4
1 2
3
1 2 9
5 3 8
4 6 7 
Case #1: 1 2
Case #2: 6 4

提示

Limits

1T1001 \le T \le 100.

Small dataset (Test Set 1 - Visible)

1S101 \le S \le 10

Large dataset (Test Set 2 - Hidden)

1S1031 \le S \le 10^3.