progress - #!/usr/bin/python def...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#!/usr/bin/python # def longest_increasing_subsequence(scores): """ This function takes a list of scores, and returns the longest increasing subsequence of those scores. It uses dynamic programming and finds the answer in a bottom up manner. """ if len(scores) == 0: #if there's nothing in the score, return [] return [] l = {} #dictionary to keep track of longest increasing subsequence ending at i parent = {} #dictionary to keep track of parents l[0] = 0 #base case: length of the longest increasing subsequence ending at i is 0 for i in range(len(scores)): #loop through all scores maxl = 0 #maxl is to keep track of the max score of subproblems for all j < i maxj = -1 #maxj is to keep track of the parent for the max score of subproblems for all j < i for j in range(i): #loop through all j < i if scores[j] < scores[i] and l[j] > maxl: #if i can be added after j and the score of the subproblem to j is the max so far maxl = l[j] #update maxl maxj = j #update maxj #print maxj l[i] = 1 + maxl
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/05/2010 for the course COMPUTER S 700 taught by Professor Joewhite during the Spring '10 term at Universidad San Martín de Porres.

Ask a homework question - tutors are online