Computer Science, asked by praveengugulothu26, 1 day ago

Sindhu has set of numbers which are placed in an order. Sindhu needs our help in finding the maximum sum formed by the elements of the array in the increasing sequence of the given elements. Input Format The first line consist of size of the array. TH second line consist of an array elements. Output Format The output consists of an integer value.sample input:5
1 2 3 4 5
sample output:
15​

Answers

Answered by sariyamasury
2

Answer:

hshdhshdndghhzhdbdbdjfjfndbdhdndhd

Answered by Jasleen0599
0

PYTHON CODE

import sys

def MSIS(nums, i=0, prev=-sys.maxsize, total=0):

   if i == len(nums):

       return total

   excl = MSIS(nums, i + 1, prev, total)

   incl = total

   if nums[i] > prev:

       incl = MSIS(nums, i + 1, nums[i], total + nums[i])

   return max(incl, excl)

if __name__ == '__main__':

   nums = [1,2,3,4]

   print('The maximum sum of the increasing subsequence is', MSIS(nums))

Output:

15

  • A common variant of the Longest Increasing Subsequence (LIS) problem is the Maximum Sum Increasing Subsequence (MSIS) problem. Recursion will be used to address this issue. There are two options for each item:
  • If the current item is greater than the preceding element in the MSIS, include it in the MSIS and repeat for the remaining items.
  • Recur for the remaining items while excluding the current item from MSIS.
  • Return the highest amount we can get after including or removing the current item. When there are no items left would be the recursion's base case.

#SPJ5

Similar questions