Maximum path 3 - MarisaOJ: Marisa Online Judge

Maximum path 3

Time limit: 1000 ms
Memory limit: 256 MB
The forest is in the form of an $n \times n$ grid. The cell at row $i$ and column $j$, or cell $(i, j)$, contains $A_{i, j}$ mushrooms. Marisa's journey starts from $(1, 1)$, goes to $(n, n)$, and then returns to $(1, 1)$. On the way from $(1, 1)$ to $(n, n)$, Marisa can move to cell $(i + 1, j)$ or $(i, j + 1)$. On the way back from $(n, n)$ to $(1, 1)$, Marisa can move to cell $(i - 1, j)$ or $(i, j - 1)$. What is the maximum number of mushrooms Marisa can collect? Of course, mushrooms cannot be collected more than once in the same cell. ### Input - The first line contains the integer $n$. - The next $n$ lines each contain $n$ integers representing the grid. ### Output - A single integer representing the maximum number of mushrooms Marisa can collect. ### Constraints - $1 \le n \le 50$ - $0 \le A_{i, j} \le 1000$. ### Example Input: ``` 4 1 0 0 4 0 0 6 0 0 0 0 0 5 0 0 0 ``` Output: ``` 12 ```