
- Data Structures & Algorithms
- DSA - Home
- DSA - Overview
- DSA - Environment Setup
- Algorithm
- DSA - Algorithms Basics
- DSA - Asymptotic Analysis
- DSA - Greedy Algorithms
- DSA - Divide and Conquer
- DSA - Dynamic Programming
- Data Structures
- DSA - Data Structure Basics
- DSA - Array Data Structure
- Stack & Queue
- DSA - Stack
- DSA - Expression Parsing
- DSA - Queue
- Searching Techniques
- DSA - Linear Search
- DSA - Binary Search
- DSA - Interpolation Search
- DSA - Hash Table
- Sorting Techniques
- DSA - Sorting Algorithms
- DSA - Bubble Sort
- DSA - Insertion Sort
- DSA - Selection Sort
- DSA - Merge Sort
- DSA - Shell Sort
- DSA - Quick Sort
- Graph Data Structure
- DSA - Graph Data Structure
- DSA - Depth First Traversal
- DSA - Breadth First Traversal
- Tree Data Structure
- DSA - Tree Data Structure
- DSA - Tree Traversal
- DSA - Binary Search Tree
- DSA - AVL Tree
- DSA - Spanning Tree
- DSA - Heap
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Maximum Sum Increasing Subsequencen
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 [j], then subSeqLen[i] := subSeqLen[j] done done add arr[i] into subSeqLen[i] res := subSeqLen[0] for all values of subSeqLen, do if sum of subSeqLen[i] > sum of subSeqLen[res], then res := subSeqLen[i] done print the values of res. End
Example
#include <iostream> #include <vector> using namespace std; int findAllSum(vector<int> arr) { //find sum of all vector elements int sum = 0; for(int i = 0; i<arr.size(); i++) { sum += arr[i]; } return sum; } void maxSumSubSeq(int arr[], int n) { vector <vector<int> > subSeqLen(n); //max sum increasing subsequence ending with arr[i] subSeqLen[0].push_back(arr[0]); for (int i = 1; i < n; i++) { //from index 1 to all for (int j = 0; j < i; j++) { //for all j, j<i if ((arr[i] > arr[j]) && (findAllSum(subSeqLen[i]) < findAllSum(subSeqLen[j]))) subSeqLen[i] = subSeqLen[j]; } subSeqLen[i].push_back(arr[i]); //sub Sequence ends with arr[i] } vector<int> res = subSeqLen[0]; for(int i = 0; i<subSeqLen.size(); i++) { if (findAllSum(subSeqLen[i]) > findAllSum(res)) res = subSeqLen[i]; } for(int i = 0; i<res.size(); i++) cout << res[i] << " "; cout << endl; } int main() { int arr[] = { 3, 2, 6, 4, 5, 1 }; int n = 6; cout << "The Maximum Sum Subsequence is: "; maxSumSubSeq(arr, n); }
Output
The Maximum Sum Subsequence is: 3 4 5
- Related Articles
- Maximum Sum Increasing Subsequence | DP-14 in C++
- Maximum Sum Increasing Subsequence using DP in C++ program
- Maximum Sum Increasing Subsequence using Binary Indexed Tree in C++
- Maximum Sum Increasing Subsequence using Binary Indexed Tree in C++ program
- Maximum product of an increasing subsequence in C++
- Maximum product of an increasing subsequence in C++ Program
- Maximum sum alternating subsequence in C++
- Maximum Sum Decreasing Subsequence in C++
- Longest Increasing Subsequence
- Maximum sum increasing subsequence from a prefix and a given element after prefix is must in C++
- Maximum sum alternating subsequence in C++ program
- Maximum product of an increasing subsequence of size 3 in C++
- Maximum product of an increasing subsequence of size 3 in C++ program
- Maximum subsequence sum such that no three are consecutive
- Longest Increasing Subsequence in Python

Advertisements