1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 7 const int MAXN = 210; 8 9 int dp[MAXN][MAXN]; 10 int p[MAXN]; 11 int n, T; 12 13 int main() { 14 scanf("%d", &T); 15 while(T--) { 16 scanf("%d", &n); 17 for(int i = 1; i <= n; ++i) scanf("%d", &p[i]); 18 for(int i = 0; i <= n; ++i) 19 for(int j = 0; j <= n; ++j) dp[i][j] = 0; 20 for(int i = 1; i <= n; ++i) { 21 int t = 0; 22 for(int j = 1; j <= n; ++j) { 23 dp[i][j] = dp[i - 1][j]; 24 if(p[i] > p[n - j + 1]) t = max(t, dp[i][j]); 25 if(p[i] == p[n - j + 1]) dp[i][j] = t + 1; 26 } 27 } 28 for(int i = 1; i <= n; ++i) 29 for(int j = 1; j <= n; ++j) dp[i][j] = max(dp[i][j], dp[i][j - 1]); 30 int ans = 0; 31 for(int i = 1; i <= n; ++i) 32 ans = max(ans, 2 * dp[i][n - i + 1] - 1); 33 for(int i = 1; i < n; ++i) 34 ans = max(ans, 2 * dp[i][n - i]); 35 printf("%d\n", ans); 36 } 37 }
HDU 4512 吉哥系列故事——完美队形(LCIS),布布扣,bubuko.com
原文:http://www.cnblogs.com/oyking/p/3704086.html