
- 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
Count all increasing subsequences in C++
In this tutorial, we will be discussing a program to find the number of increasing sequences.
For this we will be provided with an array containing digits 0 to 9. Our task is to count all the sequences present in the array such that the next element is greater than the previous element.
Example
#include<bits/stdc++.h> using namespace std; //counting the possible subsequences int count_sequence(int arr[], int n){ int count[10] = {0}; //scanning each digit for (int i=0; i<n; i++){ for (int j=arr[i]-1; j>=0; j--) count[arr[i]] += count[j]; count[arr[i]]++; } //getting all the possible subsequences int result = 0; for (int i=0; i<10; i++) result += count[i]; return result; } int main(){ int arr[] = {3, 2, 4, 5, 4}; int n = sizeof(arr)/sizeof(arr[0]); cout << count_sequence(arr,n); return 0; }
Output
14
- Related Articles
- Increasing Subsequences in C++
- Count all subsequences having product less than K in C++
- Count of subsequences having maximum distinct elements in C++
- Print all subsequences of a string in C++
- Count Strictly Increasing Subarrays in C++
- Count of AP (Arithmetic Progression) Subsequences in an array in C++
- Print all subsequences of a string using ArrayList in C++
- Program to count number of unique subsequences of a string in C++
- Print all subsequences of a string using Iterative Method in C++
- Program to find number of increasing subsequences of size k in Python
- Count the number of non-increasing subarrays in C++
- Distinct Subsequences in C++
- Count permutations that are first decreasing then increasing in C++
- Distinct Subsequences II in C++
- Distinct Subsequences in C++ Programming

Advertisements