- 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 subsequence sum such that no three are consecutive

In this tutorial, we will be discussing a program to find maximum subsequence sum such that no three are consecutive.

For this we will be provided with a series of positive integers. Our task is to find the maximum sum without taking in their consecutive positive integers in the sum value.

## Example

#include <bits/stdc++.h> using namespace std; //returning maximum subsequence without involving //three consecutive numbers int maxSumWO3Consec(int arr[], int n) { int sum[n]; if (n >= 1) sum[0] = arr[0]; if (n >= 2) sum[1] = arr[0] + arr[1]; if (n > 2) sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2])); for (int i = 3; i < n; i++) sum[i] = max(max(sum[i - 1], sum[i - 2] + arr[i]), arr[i] + arr[i - 1] + sum[i - 3]); return sum[n - 1]; } int main() { int arr[] = { 100, 1000 }; int n = sizeof(arr) / sizeof(arr[0]); cout << maxSumWO3Consec(arr, n); return 0; }

## Output

1100

- Related Articles
- Maximum subsequence sum such that no three are consecutive in C++ Program
- Maximum sum such that no two elements are adjacent in C++
- Maximum sum such that no two elements are adjacent - Set 2 in C++
- Maximum sum in circular array such that no two elements are adjacent in C++
- Maximum sum such that no two elements are adjacent Alternate Method in C++ program
- Program to print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime Using C++
- Maximum sum of nodes in Binary tree such that no two are adjacent in C++
- Maximum sum of nodes in Binary tree such that no two are adjacent | Dynamic Programming In C++
- Maximum sum in a 2 x n grid such that no two elements are adjacent in C++
- Find minimum sum such that one of every three consecutive elements is taken in C++
- Maximum sum of nodes in Binary tree such that no two are adjacent using Dynamic Programming in C++ program
- Maximum Sum Increasing Subsequence\n
- Maximum sum alternating subsequence in C++
- Maximum Sum Decreasing Subsequence in C++
- Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program

Advertisements