1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
typedef long NodeScore;
typedef std::pair< unsigned, unsigned > Coord;
typedef std::vector< Coord > Path;
static const NodeScore grid[4][4] = {
{ 12, -16, 10, -12 },
{ -16, 13, -14, 7 },
{ 7, -4, 16, -15 },
{ -7, 16, -9, 8 }
};
// c is the coordinate you are currently at. (0,0) is the top left; (3,3) is the destination.
// usedSpecial is a flag indicating whether or not the special bonus move (up or left) has been used.
// pathSoFar is the list of coordinates visited so far to get to c.
// scoreSoFar is the sum of the grid values on pathSoFar.
// bestScore and bestPath are used to keep track of the highest score and its associated path found so far.
//
// When c == (3,3), you are at the end of the recursion. At that time, see if the score so far is higher
// than the bestScore and update accordingly.
// If you are not at the end yet (3,3), then you will recursively call solve_grid up to four times, depending
// upon whether it is possible to move up, down, left, or right.
void solve_grid( Coord c, bool usedSpecial, Path pathSoFar, NodeScore scoreSoFar,
NodeScore& bestScore, Path& bestPath )
{
}
int main() {
Path bestPath;
NodeScore bestScore( 0 );
solve_grid( Coord( 0U, 0U ), false, Path(), 0, bestScore, bestPath );
}
| |