Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help me correct my code using bitlist to solve this question or if you can code it again using bitlist will be much

can someone help me correct my code using bitlist to solve this question or if you can code it again using bitlist will be much appreciated. thanks. image text in transcribed
image text in transcribed
image text in transcribed
Task 2: Maximum sum increasing sub-sequence (4 Marks) Create a Python module called max sum.py. Within this module implement the following task. (You may not import any other libraries or modules.) Given an non-empty list of integers, write a function max.sum(lst) that return a list of length of 2. The first element in output list should be an integer value representing the greatest sum that can be generated from a strictly-increasing sub-sequence in the list. The second element should a list of the numbers in that sub- sequence. A sub-sequence is defined as a set of numbers that are not necessarily adjacent but in the same order as they appear in the list. Assume that there will be only one increasing sub-sequence with the greatest sum. Input: a non-empty list of integers Output: returns a list of length of 2. The first element in output list should be an integer value representing the greatest sum that can be generated from a strictly-increasing sub-sequence in the list. The second element should a list of the numbers in that sub-sequence. Examples a) Given 1st1-[-1], calling max sum (1st1), will return [-1,[-1]]. b) Given 1st2-[10,70,20,30,50,11,30], calling max sum (1st2), will return [110, [10, 20, 30, 50]]. c) Given 1st3=[-5,-4,-3,-2,-11, calling max.sum (1st3), will return (-1, (-1]]. d) Given 1st4-[10,15,4,5,11,14,31,25,31,23,25,31,50], calling max.sum (1st4), will return [164, [10, 11, 14, 23, 25, 31, 50]]. Marking Guide (total 4 marks) Marks are given for the correct behaviour of the different functions: (a) 2.0 marks to find all the feasible solutions. 2.0 marks to find the optimal solutions. in_8.txt O graph A.txt 1st1 = [-1] lst2 = [10,70,20,30,50,11,30] 1st3 = [-5,-4,-3,-2,-1] Ist4 = [10,15,4,5,11,14,31,25,31,23,25,31,50] def find sum(arr): summ = 0 for i in arr: sunm + i return summ finds the Sum.of. the sub seguense def max_sum(lst): n = len(lst) ans = bitlists(n) ans (01.append (lst[0]) for i in range(1, n): for j in range(i): if lst(1] > lst[j] and find_sum(ans (1]) find sum(feasible)): feasible - x 31 32 33 if sum(feasible) find_sum(feasible)): 31 32 feasible = x 33 34 if sum(feasible)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

=+Where does the focus of labor relations lie? Is it collective

Answered: 1 week ago

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago