标签:
给一个数列, 在里面选出一些数组成一个对称的数列, 数的顺序不能打乱。 使得左半边是一个严格递增的数列, 右边递减, 并且a[i] = a[n-i+1]。
就是一个对称的LCIS..
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; int dp[205], a[205], b[205]; int main() { int n, m, t; cin>>t; while(t--) { cin>>n; int ans = 0; for(int i = 1; i<=n; i++) { cin>>a[i]; b[n-i+1] = a[i]; } mem(dp); for(int i = 1; i<=n; i++) { int best = 0; for(int j = 1; j<=n-i+1; j++) { if(a[i]==b[j]) { if(j == n-i+1) dp[j] = max(dp[j], dp[best]+1); else dp[j] = max(dp[best]+2, dp[j]); } else if(a[i]>b[j]&&dp[j]>dp[best]) { best = j; } if(dp[j]>ans) ans = dp[j]; } } cout<<ans<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/yohaha/p/5276942.html