Skip to content

Instantly share code, notes, and snippets.

@jesuyedavid
Created April 21, 2018 21:16
Show Gist options
  • Save jesuyedavid/bf7845ac5b4b7ea9645d177bcc5ddfb1 to your computer and use it in GitHub Desktop.
Save jesuyedavid/bf7845ac5b4b7ea9645d177bcc5ddfb1 to your computer and use it in GitHub Desktop.
A fisherman is in a rectangular sea. The value of the fish at point (i, j) in the sea is specified by an n × m 2D array A. Write a program that computes the maximum value of fish a fisherman can catch on a path from the upper leftmost point to the lower rightmost point. The fisherman can only move down or right
def maxFish(grid):
nc=grid[0]
for i in range(len(nc)):
if(i!=0):
nc[i]+=grid[0][i-1]
for i in range(1,len(grid)):
for j in range(len(grid[0])):
if (j!=0):
nc[j]=max(grid[i][j]+nc[j], nc[j-1]+grid[i][j])
else:
nc[j]+=grid[i][j]
return nc[len(grid[0])-1]
grid=[[1,3,0],
[0,1,5],
[3,2,4]]
print(maxFish(grid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment