1187make array strictly increasing
sort(arr2.begin(),arr2.end()); int n=arr1.size(); int m=unique(arr2.begin(),arr2.end())-arr2.begin(); int dp[n+2][m+2]; memset(dp,-1,sizeof(dp)); dp[0][m]=0; for(int i=0;i<m;i++) dp[0][i]=1; for(int i=0;i<n-1;i++) { for(int j=0;j<=m;j++) { if(dp[i][j]==-1) continue; int tmp=(j==m?arr1[i]:arr2[j]); if(arr1[i+1]>tmp&&(dp[i+1][m]==-1||dp[i+1][m]>dp[i][j])) { dp[i+1][m]=dp[i][j]; } int idx=upper_bound(arr2.begin(),arr2.begin()+m,tmp)-arr2.begin(); if(idx<m&&(dp[i+1][idx]==-1||dp[i+1][idx]>dp[i][j]+1)) dp[i+1][idx]=dp[i][j]+1; } } int ans=-1; for(int i=0;i<=m;i++) { if(dp[n-1][i]==-1) continue; if(ans==-1||ans>dp[n-1][i]) ans=dp[n-1][i]; } return ans;
1,严格递增,严格递减。
2,