AlgoUniversity
  • Go Back
Discussion
Max Gold :

Author

Akshay Sharma

Difficulty Level : Hard

Submissions : 562

Asked In : Flipkart

Marks :100

: 4 | : 6

In a gold mine grid of size M*N, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.

Return the maximum amount of gold you can collect under the following conditions:

Every time you are located in a cell you will collect all the gold in that cell.

You can walk one step from your position to the left right up or down.

You can't visit the same cell more than once.

Never visit the cell with 0 Gold.

You can start and stop collecting gold from any position in the grid that has some gold.

Input

The first line of input contains two integers M, N the number of rows and columns in the matrix ($$$1 \le M, N \le 15$$$).

Next M*N line contains the element of the matrix.

Output

For each test case print, the maximum amount of gold u can collect

Example

Input
3 3
1 0 0
0 44 0
0 0 12
Output
44

Note

The Number of cells that contain gold is less than 25.

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.