Hdu5256 sequence transformation longest incrementing subsequence
// For a sequence a, the minimum number of elements changed to a monotonically incrementing Sequence
// For this sequence, the minimum replacement is to find the longest child sequence that does not need to be replaced.
// Therefore, the longest incrementing subsequence of a [I]-I is obtained.
# Include
# Include
# Include
# Include
Using namespace std;
Const int maxn = 100010;
Int B [maxn];
Int find (int l, int r, int num)
{
While (l <= r)
{
Int mid = (l + r)> 1;
If (B [mid] <= num)
L = mid + 1;
Else
R = mid-1;
}
Return l;
}
Int main ()
{
Int T;
Int n;
Int;
Scanf ("% d", & T );
Int cas = 0;
While (T --)
{
Scanf ("% d", & n );
Int len = 0;
For (int I = 1; I <= n; I ++)
{
Scanf ("% d", & );
If (I = 1)
{
B [++ len] = a-I;
Continue;
}
Int pos = find (1, len, a-I );
B [pos] = a-I;
If (pos> len) len ++;
}
Printf ("Case # % d: \ n", ++ cas );
Printf ("% d \ n", n-len );
}
Return 0;
}