
- 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 subsequences having product less than K in C++
In this tutorial, we will be discussing a program to find the number of sub sequences having product less than K.
For this we will be provided with non-negative array and a value k. Our task is to find all the subsequences in the array having product less than k.
Example
#include <bits/stdc++.h> using namespace std; //counting subsequences with product //less than k int count_sub(vector<int> &arr, int k){ int n = arr.size(); int dp[k + 1][n + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= k; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i][j - 1]; if (arr[j - 1] <= i && arr[j - 1] > 0) dp[i][j] += dp[i/arr[j-1]][j-1] + 1; } } return dp[k][n]; } int main(){ vector<int> A; A.push_back(1); A.push_back(2); A.push_back(3); A.push_back(4); int k = 10; cout << count_sub(A, k) << endl; }
Output
11
- Related Articles
- Count of alphabets having ASCII value less than and greater than k in C++
- Subarray Product Less Than K in C++
- Count pairs in a sorted array whose product is less than k in C++
- Count all sub-sequences having product
- Count the number of words having sum of ASCII values less than and greater than k in C++
- Python – Elements with factors count less than K
- Count ordered pairs with product less than N in C++
- Count all increasing subsequences in C++
- Count of subsequences having maximum distinct elements in C++
- Count all sub-arrays having sum divisible by k
- Product of all Subsequences of size K except the minimum and maximum Elements in C++
- Largest number less than X having at most K set bits in C++
- Find the Number of subarrays having sum less than K using C++
- Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k in C++
- Count subarrays with all elements greater than K in C++

Advertisements