Created
December 19, 2016 01:11
-
-
Save MathisHammel/4e10d6f5eefc38f1d7287225415b639b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maxsubarr(arr): | |
h=len(arr) | |
w=len(arr[0]) | |
bestsum=arr[0][0] | |
bestcoords=None | |
for lbeg in range(h): | |
for cbeg in range(w): | |
for lend in range(lbeg,h): | |
for cend in range(cbeg,h): | |
subsum=0 | |
for l in range(lbeg,lend+1): | |
for c in range(cbeg,cend+1): | |
subsum+=arr[l][c] | |
if subsum==bestsum: | |
print "equal",bestsum | |
if subsum>=bestsum: | |
bestsum=subsum | |
bestcoords=((lbeg,cbeg),(lend,cend)) | |
return bestcoords |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment