题面:
#include<bits/stdc++.h>
using namespace std;
int t, n;
int a[100005], dp[100005];//以a[i]为结尾的最大连续子序列之和
bool check(int x){
if (x % 2 == 0) return 1;
if (x % 2 == 1) return 0;
}
int main(){
cin >> t;
while (t --){
cin >> n;
for (int i = 1;i <= n;++ i){
cin >> a[i];
dp[i] = 1;
}
for (int i = 1;i <= n;++ i)
for (int j = 1; j <= i - 1;++ j){
if (check (a[i]) != check (a[j]))
dp[i] = max (dp[i] + a[i], dp[j]);
}
int maxn = -1e8;
for (int i = 1;i <= n;++ i)
maxn = max (maxn, dp[i]);
cout << maxn << endl;
}
return 0;
}