Topic links: https://vjudge.net/problem/HDU-5256
Meaning of the questions: to a number of columns, each is different and is an integer number, is seeking a minimum need to modify the number of times in order to make the number listed as a strictly increasing.
Ideas: First, for an integer number of columns of a strictly increasing a, there must be a [i]> = a [i-1] +1, therefore, a [i] -i> = a [i-1] - (i- 1), as a clue, we generate a new series b [i] = a [i] -i, then b [i]> = b [i-1], in other words, strictly increasing the number of columns a, equivalent b in number of columns is not lowered, therefore, increase the longest sequence length nb is the minimum number of modifications.
code show as below:
1 #include<cstdio> 2 #include<algorithm> 3 #include<iostream> 4 #include<cstring> 5 using namespace std; 6 const int max_v=100010; 7 const int INF=10000000; 8 int dp[max_v],n,a[max_v]; 9 10 int solve(){ 11 memset(dp,0x3f,sizeof(dp)); 12 for(int i=0;i<n;i++) 13 *upper_bound(dp,dp+n,a[i])=a[i]; 14 return (lower_bound(dp,dp+n,0x3f3f3f)-dp); 15 } 16 int main(){ 17 int t; 18 scanf("%d",&t); 19 for(int i=1;i<=t;i++){ 20 scanf("%d",&n); 21 for(int i=1;i<=n;i++){ 22 scanf("%d",&a[i-1]); 23 a[i-1]=a[i-1]-i+1; 24 } 25 printf("Case #%d:\n%d\n",i,n-solve()); 26 } 27 return 0; 28 }