Last active
August 29, 2015 14:19
-
-
Save ScottBuchanan/5bcc2e132dd157ccbcba to your computer and use it in GitHub Desktop.
4.6
This file contains hidden or 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
DP(i,j): | |
soln = i*n array with val inited to -1 | |
return helper(i,j, soln) | |
helper(i, j, soln): | |
#first iterate through all the smallest lens, then build on those | |
for 1 to (j-i) as len: | |
#make j always len away from i | |
j = i + len - 1 | |
bestsofar = infin | |
for i to j as k: | |
value = max(soln_check(soln, i, k-1), soln_check(soln, k+1, j)) + cost(k) | |
if value > bestsofar: | |
bestsofar = value | |
return soln[i][j] | |
soln_check(soln, i, j): | |
if j < i: | |
return 0 | |
if i == j: | |
return cost(j) | |
else: | |
return soln[i][j] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment