
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Maximum Sum Increasing Subsequence | DP-14 in C++
In this tutorial, we will be discussing a program to find maximum Sum Increasing Subsequence.
For this we will be provided with an array containing N integers. Our task is to pick up elements from the array adding to the maximum sum such that the elements are in sorted order
Example
#include <bits/stdc++.h> using namespace std; //returning the maximum sum int maxSumIS(int arr[], int n) { int i, j, max = 0; int msis[n]; for ( i = 0; i < n; i++ ) msis[i] = arr[i]; for ( i = 1; i < n; i++ ) for ( j = 0; j < i; j++ ) if (arr[i] > arr[j] && msis[i] < msis[j] + arr[i]) msis[i] = msis[j] + arr[i]; for ( i = 0; i < n; i++ ) if ( max < msis[i] ) max = msis[i]; return max; } int main() { int arr[] = {1, 101, 2, 3, 100, 4, 5}; int n = sizeof(arr)/sizeof(arr[0]); cout << "Sum of maximum sum increasing subsequence is "<< maxSumIS( arr, n ) << endl; return 0; }
Output
Sum of maximum sum increasing subsequence is 106
- Related Articles
- Maximum Sum Increasing Subsequence using DP in C++ program
- Maximum Sum Increasing Subsequence\n
- 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++
- Maximum sum alternating subsequence in C++ program
- Maximum sum increasing subsequence from a prefix and a given element after prefix is must in C++
- Maximum product of an increasing subsequence of size 3 in C++
- Maximum sum rectangle in a 2D matrix | DP-27 in C++
- Longest Increasing Subsequence
- Maximum product of an increasing subsequence of size 3 in C++ program
- Longest Increasing Subsequence in Python

Advertisements