Back to Browse

Count all subsequences having product less than k | dynamic programming | step by step

7.3K views
May 19, 2021
23:25

Joey'sTech brings you one amazing DP problem in its dynamic programming tutorial series. I am working hard on bringing DP problems of varying difficulties for you which will help you develop your aptitude for dynamic programming. Let me tell you this that if you watch any video with a notepad and a pen, follow along well and then the next day you do the problem again without looking at the explanation again, you will surely learn a new approach to crack dynamic programming problems. ********************************* Top Books to master algorithms ********************************* Introduction to Algorithms https://amzn.to/3h4ze7Q Algorithms 4th edition https://amzn.to/2WVjs8F Programming Interview Problems https://amzn.to/38HAn0J ********************************* ********************************************* Top Headset gear for music while you code ********************************************* Donerton Wireless Buds https://amzn.to/3jMriKp Senheiser HD559 Open Back headphone https://amzn.to/3h4oIO8 Sony WH-1000XM4 https://amzn.to/38EsA3Q I mean the approach you learn in any video will be used in some or the other problem. The dynamic programming problem that you will learn in this video is `Count all subsequences having product less than k' The problem statement is quite small and easy to understand but the solution requires little bit of mental effort and experience in solving DP problems. I will give you a slight hint here. If you have experience in solving the 01 Knapsack problem then understanding this problem will be a piece of cake. For this dynamic programming problem, you are given an array { 1 , 2 , 3 , 4 } and a variable k of which the value is 10. You are required to find all the subsequences from this array for which the product of the integers does not exceed k which is 10. Here are some examples of such subsequences - {1}, {2}, {3}, {4}, {1,2}, {2,3}, {1,2,3} Observe that the product of integers in these subsequences does not exceed 10. Below is an example that won't satisfy the condition - {1,3,4} Clearly, the product of these integers is 12 which exceeds 10, hence this subsequence won't fall in the solution. In this video of DP, you will learn to construct a dynamic programming algorithm to find the solution of this problem using a matrix. Thus I recommend to learn how to build a dynamic programming algorithm for the problem of 'Count all subsequences having product less than k', you watch this video till the end.

Download

0 formats

No download links available.

Count all subsequences having product less than k | dynamic programming | step by step | NatokHD