I did this question once before. I didn't want to understand it at the time, wa. I saw it again today. After reviewing the question, I confirmed that this was the largest ascending subsequence. At that time, I was very excited, however, I don't know how to identify whether there is an intermediate highest point. After thinking for a long time, I still don't want to understand it, and I still want to check the problem-solving report .....
This algorithm is very clever. It uses brute force to enumerate all cases where there are intermediate points and no intermediate points, and then obtains the largest one. What is this? What about semi-DP semi-violence? What is the combination of violence and aesthetics?
For the algorithm of the maximum public ascending subsequence, I have already explained it in a blog, so I will not explain it anymore.
Link: hdu 1423 (maximum public ascending subsequence)
[Cpp] # include <stdio. h>
# Include <string. h>
# Define N 205
Int a [N], B [N], ans [N];
Int Max (int x, int y)
{
Return x> y? X: y;
}
Int LCIS (int x, int y)
{
Memset (ans, 0, sizeof (ans ));
Int sum;
Int I, j, k;
For (I = 1; I <= x; I ++)
{
K = 0;
For (j = 1; j <= y; j ++)
{
If (B [j] <a [I] & ans [k] <ans [j])
K = j;
If (B [j] = a [I])
Ans [j] = ans [k] + 1;
}
}
Sum = 0;
For (I = 1; I <= y; I ++)
Sum = Max (sum, ans [I]);
Return sum * 2;
}
Int main ()
{
Int T;
Scanf ("% d", & T );
While (T --)
{
Int n;
Int I;
Scanf ("% d", & n );
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & a [I]);
B [n-I + 1] = a [I];
}
Int ans;
Ans = 0;
For (I = 1; I <= n; I ++)
{
Ans = Max (LCIS (I, n-I), ans );
Ans = Max (LCIS (I, n-I + 1)-1, ans );
}
Printf ("% d \ n", ans );
}
Return 0;
}
# Include <stdio. h>
# Include <string. h>
# Define N 205
Int a [N], B [N], ans [N];
Int Max (int x, int y)
{
Return x> y? X: y;
}
Int LCIS (int x, int y)
{
Memset (ans, 0, sizeof (ans ));
Int sum;
Int I, j, k;
For (I = 1; I <= x; I ++)
{
K = 0;
For (j = 1; j <= y; j ++)
{
If (B [j] <a [I] & ans [k] <ans [j])
K = j;
If (B [j] = a [I])
Ans [j] = ans [k] + 1;
}
}
Sum = 0;
For (I = 1; I <= y; I ++)
Sum = Max (sum, ans [I]);
Return sum * 2;
}
Int main ()
{
Int T;
Scanf ("% d", & T );
While (T --)
{
Int n;
Int I;
Scanf ("% d", & n );
For (I = 1; I <= n; I ++)
{
Scanf ("% d", & a [I]);
B [n-I + 1] = a [I];
}
Int ans;
Ans = 0;
For (I = 1; I <= n; I ++)
{
Ans = Max (LCIS (I, n-I), ans );
Ans = Max (LCIS (I, n-I + 1)-1, ans );
}
Printf ("% d \ n", ans );
}
Return 0;
}