title: Find the maximum sum path of a matrix from left column to right column?
body: <p>Jeff loves playing games, Gluttonous snake( an old game in NOKIA era ) is one of his favourites. However, after playing gluttonous snake so many times, he finally got bored with the original rules. In order to bring new challenge to this old game, Jeff introduced new rules :</p>
  
  <ol>
  <li><p>The ground is a grid, with n rows and m columns(1 &lt;= n, m &lt;= 500).</p></li>
  <li><p>Each cell contains a value v (-1 vi 99999), if v is -1, then this cell is blocked, and the snake  ≤  ≤  can not go through, otherwise, after the snake visited this cell, you can get v point.</p></li>
  <li><p>The snake can start from any cell along the left border of this ground and travel until it finally stops at one cell in the right border.</p></li>
  <li><p>During this trip, the snake can only go up/down/right, and can visit each cell only once. 
  Special cases :</p></li>
  </ol>
  
  <p>a. Even in the left border and right border, the snake can go up and down.</p>
  
  <p>b. When the snake is at the top cell of one column, it can still go up, which demands the player to  pay all current points , then the snake will be teleported to the bottom cell of this column and vice  versa. </p>
  
  <p>After creating such a new game, Jeff is confused how to get the highest score. Please help him to write a program to solve this problem. Input  The first line contains two integers n (rows) and m (columns), (1 &lt;= n, m &lt;= 500), separated by a  single space.  Next n lines describe the grid. Each line contains m integers vi (-1 vi 99999)  ≤   ≤   vi = -1 means the cell is blocked. Output  Output the highest score you can get. If the snake can not reach the right side, output -1.</p>
  
  <p>Input :</p>
  
  <p>4 4</p>
  
  <p>-1 4 5 1</p>
  
  <p>2 -1 2 4</p>
  
  <p>3 3 -1 3</p>
  
  <p>4 2 1 2</p>
  
  <p>Output :</p>
  
  <p>23</p>