For a digit N we define LIS Array as
Longest strictly increasing subsequence of digits ending with that digit.
For example, let us say 4-digit number is 1531, then the LIS array would be [1, 2, 2, 1].
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).
Here i am using bitmasking algorithm
for(int i=2;i<=n;i++){
int x = Lis[i];
if(x==1){
for(int j=1;j<(1<<10);j++){
int last=-1;
int len=0;
for(int k=9;k>=0;k--)
if((j&(1<<k))!=0){
len++;
if(len==1)
last=k;
}
for(int k=0;k<=last;k++){
dp[1<<k][i] = (dp[1<<k][i]+ dp[j][i-1])%mod;
}
}
continue;
}
for(int j=1;j<(1<<10);j++){
int last=-1;
int len=0;
for(int k=9;k>=0;k--)
if((j&(1<<k))!=0){
len++;
if(len==1)
last=k;
}
if(len+1!=x) continue;
for(int k=last+1;k<10;k++)
dp[j|(1<<k)][i] = (dp[j|(1<<k)][i]+ dp[j][i-1])%mod;
}
}
But it's not working correctly ? Can anyone explain me correct approach to deal with this ?