---------------------------------------------------
Description:
I haven't understood this question many times. English is not enough.
It is required to find the non-conflicting "interesting" subsequence.
--------------------------------------------------
Answer:
Use dp. Mark the previous position where s [I] appears. If s [I] is not displayed, it is recorded as 0.
Dp [I] = max (dp [I-1], dp [last [s [I] + 1); last [s [I] is updated at the same time.
This method is correct: because the question is a non-conflicting string, this method will ignore the various strings between I and last [s [I. If a certain number between I and last [s [I] is selected as the starting point, the string ending with s [I] is obviously ignored. In addition, if there are 123121 overlapping strings, we will obviously choose to separate them, so we can only update the s [I] We encountered at the last update.
--------------------------------------------------
Source code:
[Cpp]
# Include <stdio. h>
# Define max (a, B) (a)> (B )? (A) (B ))
Int main ()
{
Int t = 0, n = 0;
Int s [100010];
Int I = 0;
Int dp [100010], last [100010];
Int ans = 0;
Scanf ("% d", & t );
While (t --)> 0)
{
Scanf ("% d", & n );
Ans = 0;
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & s [I]);
Last [s [I] = 0;
}
Last [s [1] = 1;
Dp [1] = 0;
For (I = 2; I <= n; I ++)
{
If (last [s [I]! = 0)
Dp [I] = max (dp [I-1], dp [last [s [I] + 1 );
Else
Dp [I] = dp [I-1];
Last [s [I] = I;
Ans = max (dp [I], ans );
}
Printf ("% d \ n", ans );
}
Return 0;
}
Author: violet_xrym