Problem 2: Starry Field (2017/2018)

In this task we solve an optimization problem: find the optimal strategy in a simple one-player game.

We are given a rectangular grid, with a number or a star in each square. We go from the top row to the bottom row. Our path must start in the top row, and in each step go either to the square directly below the previous square, or one square to the left or right (see the picture).
0 5 8 7 8 2 8 0 2 8 2 9 6 7 4 8 0 5 3 5 8 2 1 4 6 0 6 4 9 8 6 7 7 7 3 6 0 0 8 5 5 2 4 7 9 8 0 5 9 7 3 6 6 8 5 0 8 4 8 2 1 3 0 4 1 5 8 8 0 4 9 5 6 2 9 1 9 9 4 6 4 0 1 3 4 1 2 5 3 1
The score is calculated as follows. Thus, we get 17+18+114 = 149 points by following the path on the picture. This is the highest possible score on this board.

Your task is to write a program which, given a board, finds the path which gives the highest possible score. For simplicity, it is enough to output only this highest score (you are not required to output the optimal path itself).

Testing program in C++

#include <iostream>
#include <vector>
#include <array>
#include <string>

using namespace std;

// you can add extra includes or auxiliary functions/variables if needed

int starry_field(const vector<string>& board) {
  // write your solution here
  return 90;
  }

int main() {

  vector<string> board = {
    "0587828028", 
    "2967480535", 
    "82*14606*4", 
    "*986777360", 
    "0*85524798", 
    "059*736685", 
    "084821304*", 
    "15880495*6", 
    "291*994640", 
    "13*412531*", 
    };

  int expected_result = 149;

  auto result = starry_field(board);
  cout << "Your result: " << result << "\n";
  if(result == expected_result)
    cout << "Result correct!\n";
  else
    cout << "Result incorrect!\n";
  return 0;
  }

Testing program in Python

# add your own imports and auxiliary functions if needed

def starry_field(board):
  # implement your solution here
  return 90

board = [
  "0587828028", 
  "2967480535", 
  "82*14606*4", 
  "*986777360", 
  "0*85524798", 
  "059*736685", 
  "084821304*", 
  "15880495*6", 
  "291*994640", 
  "13*412531*", 
  ]
  
expected_result = 149

my_result = starry_field(board)
print("Your result is: ", my_result)

if my_result == expected_result:
  print("Result correct!")
else:
  print("Result incorrect!")

Hints

Rules