Original source: ICPC Pacific Northwest 2007
Input and output formats changed
Time Limit: 1 second
You’re given an unlimited number of pebbles to distribute across an n-by-n game board (3 ≤ n ≤ 15), where each square on the board contains some two-digit point value. A 6-by-6 board might look like this:
33 | 74 | 26 | 55 | 79 | 54 |
67 | 56 | 91 | 72 | 44 | 32 |
44 | 64 | 22 | 91 | 29 | 61 |
61 | 32 | 76 | 50 | 50 | 32 |
81 | 65 | 56 | 38 | 96 | 36 |
38 | 78 | 50 | 92 | 90 | 75 |
The player distributes pebbles across the board so that:
The goal is to maximise the number of points claimed by your placement of pebbles.
For example, it is valid (but not necessarily optimal) to place pebbles in the bolded squares below:
33 | 74 | 26 | 55 | 79 | 54 |
67 | 56 | 91 | 72 | 44 | 32 |
44 | 64 | 22 | 91 | 29 | 61 |
61 | 32 | 76 | 50 | 50 | 32 |
81 | 65 | 56 | 38 | 96 | 36 |
38 | 78 | 50 | 92 | 90 | 75 |
Write a program that reads a board from input and prints the maximum number of points attainable by an optimal pebble placement.
The first line of input consists of an integer n (3 ≤ n ≤ 15), representing the dimension of the board. n lines follow, the ith of which consists of n space-separated integers, ai, 1, ai, 2, …, ai, n (10 ≤ ai, j ≤ 99), representing the point values of the squares comprising the ith row of the board.
Output a single integer, the maximum number of points one can get by optimally distributing pebbles while respecting the two rules.
5
71 24 95 56 54
85 50 74 94 28
92 96 23 71 10
23 61 31 30 46
64 33 32 95 89
572
6
78 78 11 55 20 11
98 54 81 43 39 97
12 15 79 99 58 10
13 79 83 65 34 17
85 59 61 12 58 97
40 63 97 85 66 90
683
In sample case 1, we should take: