Sane's Monthly Algorithms Challenge: October 2008
Some ground has been selected for you to search for gold. Core samples and metal detectors have created an accurate picture of what the underground environment looks like.
The data has been simplified to an
Digging for gold can be a long and laborious process. Fortunately for you, a software-driven digging rig is making the task programmable via remote control.
With your special digging rig, you may dig from your current location to any adjacent location. However, you can not dig upwards. You start at ground-level, and you may never dig off the cube. At any time you may bring your rig back up to ground-level and repeat this process. Your task is to remotely gather as much gold as possible.
Input Specification
The first line of input contains a single integer,
The next line is blank.
.
) Rock (X
) or Gold (*
),
followed by a blank line.
The levels are listed, in order, from ground-level to the deepest level.
Output Specification
On a single line, an integer representing the amount of gold you can
retrieve. If no gold can be dug, then output
Sample Input
4
.X..
.X..
.XXX
.XXX
.X..
....
.X.X
.X..
XX..
X...
..XX
.X.*
*X*.
X...
....
*X..
Sample Output
3
Explanation
The following route is taken to get
.X..
1X..
.XXX
.XXX
.X..
234.
.X5X
.X67
XX..
X...
..XX
.X.8
*XDC
XFEB
HG.A
IX.9
In one dig we can retrieve
Below is the data's corresponding diagram. It is shown in
White is soil.
Grey is rock.
Orange is untouched gold.
Purple is retrieved gold.
Green is the path taken.
The number inside each green cube indicates the order of visitation.


Comments