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

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

#!/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 #after looping through all j in front of i, update
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern