Someone Help Correct Code Using Bitlist Solve Question Code Using Bitlist Much Appreciated Q43879609
can someone help me correct my code using bitlist to solvethis question or if you can code it again using bitlist will bemuch appreciated. thanks.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(ans Ij):check if next element bigger than current elenent in 1st. Checks for e in ans tj]: if e not in ans (1]: ans (1).append(e) ans (1). append(Lst[1]) feasible – ans (0] * find max for x in feasible: if (find sum(x) > find sum(feasible)): feasible – x 31 32 33 if sum(feasible) < 0: return (-1, (-1]1 return (feasible(-1), feasible] 34 35 36 1 Event Log max sum) 1726 LF UTF-8 4 space Python 38 (Assignment 3) %0 hon Console sum.py a 20 max_sum_test.py # find max 30 for x in feasible: if (find_sum(x) > find_sum(feasible)): 31 32 feasible = x 33 34 if sum(feasible) < ®: 35 return (-1, [-1]] return [feasible[-1], feasible] 36 37 edef bitlists(n): 38 39 first = n* [@] 40 last = n * (1] 41 [first) while res[-1] != last: res += (lex_suc(res (-1])] tadd the direct successor or. resl-1] to res res = 42 43 44 return res 45 edef lex suc(bitlst): 46 47 res = bitlst[:] i – len(res) – 1 last index while res [i] – 1: #if last index equal to 1 res [i] – 0#change last index to e i- 1 #index of 2nd last res [i] – 1 #if last index not equal to 1 then make last index 1 48 49 50 51 52 53 return res 54 print(max sum(lst1)) print (max_sum(lst2)) print (max_sum(lst3)) print (max_sum(lst4)) 55 56 57 58 59 max_sum() Show transcribed image text 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)
Expert Answer
Answer to can someone help me correct my code using bitlist to solve this question or if you can code it again using bitlist will …
OR