I have a problem in which we have an array of positive numbers and we have to make it strictly increasing by making zero or more changes to the array elements.
We ar
Changing Longest Increasing Sequence to accommodate for squeezing integral values between two successive increasing elements can ensure that we have integral values at appropriate places.
Modified LIS code:
int convert(vector v){
vector lis(v.size(), 1);
for(int i = 1; i < v.size(); i++){
for(int j = 0; j < i; j++){
if(v[i] > v[j] && lis[i] < lis[j]+1 && (i-j) <= (v[i]-v[j]))
lis[i] = lis[j]+1;
}
}
int max_lis = 0;
for(int i = 0; i < v.size(); i++)
max_lis = max(max_lis, lis[i]);
int ans = v.size() - max_lis;
return ans;
}