Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Maximum Sum Increasing Subsequence\\n
Maximum Sum Increasing subsequence is a subsequence of a given list of integers, whose sum is maximum and in the subsequence, all elements are sorted in increasing order.
Let there is an array to store max sum increasing subsequence, such that L[i] is the max sum increasing subsequence, which is ending with array[i].
Input and Output
Input:
Sequence of integers. {3, 2, 6, 4, 5, 1}
Output:
Increasing subsequence whose sum is maximum. {3, 4, 5}.
Algorithm
maxSumSubSeq(array, n)
Input: The sequence of numbers, number of elements.
Output: Maximum sum of the increasing sub sequence.
Begin define array of arrays named subSeqLen of size n. add arr[0] into the subSeqLen for i in range (1 to n-1), do for j in range (0 to i-1), do if arr[i] > arr[j] and sum of subSeqLen [i] sum of subSeqLen[res], then res := subSeqLen[i] done print the values of res. End
Example
#include#include using namespace std; int findAllSum(vector arr) { //find sum of all vector elements int sum = 0; for(int i = 0; i > subSeqLen(n); //max sum increasing subsequence ending with arr[i] subSeqLen[0].push_back(arr[0]); for (int i = 1; i arr[j]) && (findAllSum(subSeqLen[i]) res = subSeqLen[0]; for(int i = 0; i findAllSum(res)) res = subSeqLen[i]; } for(int i = 0; i Output
The Maximum Sum Subsequence is: 3 4 5
Advertisements
