title: Longest Increasing Subsequences
body: <p>For a digit N we define <strong>LIS Array</strong> as </p>
  
  <p>Longest strictly increasing subsequence of digits ending with that digit.</p>
  
  <p>For example, let us say 4-digit number is 1531, then the <strong>LIS array would be [1, 2, 2, 1].</strong><br><br> The length of longest increasing subsequence ending at first digit is 1 (the digit 1 itself) and at the second digit is 2 ([1, 5]), at third digit is also 2 ([1, 3]), and at the 4th digit is 1 (the digit 1 itself).</p>
  
  <p><a href="https://www.codechef.com/problems/DIGITLIS" rel="nofollow noreferrer">Problem Statement</a></p>
  
  <p>Here i am using bitmasking algorithm </p>
  
  <pre><code>for(int i=2;i&lt;=n;i++){
      int x = Lis[i];
  
      if(x==1){
          for(int j=1;j&lt;(1&lt;&lt;10);j++){
              int last=-1;
              int len=0;
              for(int k=9;k&gt;=0;k--)
                  if((j&amp;(1&lt;&lt;k))!=0){ 
                      len++;
                      if(len==1)
                          last=k;
                  }
  
              for(int k=0;k&lt;=last;k++){
                  dp[1&lt;&lt;k][i] = (dp[1&lt;&lt;k][i]+ dp[j][i-1])%mod;
              }
          }
  
          continue;
      }
  
      for(int j=1;j&lt;(1&lt;&lt;10);j++){
          int last=-1;
          int len=0;
          for(int k=9;k&gt;=0;k--)
              if((j&amp;(1&lt;&lt;k))!=0){ 
                  len++;
                  if(len==1)
                      last=k;
              }
          if(len+1!=x) continue;
  
          for(int k=last+1;k&lt;10;k++)
              dp[j|(1&lt;&lt;k)][i] = (dp[j|(1&lt;&lt;k)][i]+ dp[j][i-1])%mod; 
      }
  }
  </code></pre>
  
  <p>But it's not working correctly ? Can anyone explain me correct approach to deal with this ?</p>