- Related Questions & Answers
- Subarray Product Less Than K in C++
- Count of alphabets having ASCII value less than and greater than k in C++
- Count pairs in a sorted array whose product is less than k in C++
- Count ordered pairs with product less than N in C++
- Count all sub-sequences having product <= K – Recursive approach in C++
- Count the number of words having sum of ASCII values less than and greater than k in C++
- Count all increasing subsequences in C++
- Count of subsequences having maximum distinct elements in C++
- Product of all Subsequences of size K except the minimum and maximum Elements in C++
- Count subarrays with all elements greater than K in 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++
- Two Sum Less Than K in Python
- Count all sub-arrays having sum divisible by k
- Minimum swaps required to bring all elements less than or equal to k together in C++
- Count pairs with bitwise OR less than Max in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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.

#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; }

11

Advertisements