Given a m-by-n grid: every element is non-negative integer.
Constrains:
(1) a path only contain non-zero cells
(2) a path can extend to 4 directions: up, down, left, right
(3) no same cell in a path
Assumption
(4) cells with non-0 number will not form a cycle
Find the maximum path sum.
Example 1:
Input:
5 4 1 0
1 0 1 2
3 0 0 4
0 1 2 0
Output: 21
Explanation: 3 -> 1 -> 5 -> 4 -> 1 -> 1 -> 2 -> 4
Example 2:
Input:
5 4 1 3
1 0 1 0
3 0 0 4
0 1 2 0
Output: 17
Explanation: 3 -> 1 -> 5 -> 4 -> 1 -> 3