title: Count All Sub sequences having Product less than K
body: <p>Given a non-negative array, find the number of subsequences having a product smaller than K.</p>
  <p>Examples:</p>
  <p>Input : [1, 2, 3, 4]
  k = 10
  Output :11</p>
  <p>Input  : [4, 8, 7, 2]
  k = 50
  Output : 9</p>
  <p>So, We want to count the number of subsequences whose product is less than K.</p>
  <p>There are sub-problems, and it can be solved using Dynamic Programming</p>
  <p>However, I tried to write down the recursive code for better understanding.</p>
  <p>Note: I am getting an answer as 6, which is wrong.
  Can someone help me, How to foresee the correct Logic?</p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  vector&lt;int&gt; A{1, 2, 3, 4};
  
  int countSubsequence(int i, int prod, int K)
  {
      if(prod &gt; 1 &amp;&amp; prod &lt;= K)
          return 1;
          
      if(i &gt;= A.size() || prod &gt; K)
          return 0;
  
      return countSubsequence(i + 1, prod, K) + countSubsequence(i + 1, prod*A[i], K);
  }
  
  int main() 
  {
      int K = 10;
      cout &lt;&lt; countSubsequence(0, 1, K);
      
      return 0;
  }
  </code></pre>