分奇偶讨论 dp[i][j] 1---i 中以j(偶数 or 奇数)结尾的最大值
class Solution {
public:
long long maxScore(vector<int>& nums, int x) {
int n = nums.size();
vector<vector<long long>> dp(n,vector<long long> (2,0));
dp[0][0] = nums[0] + ((nums[0]%2==1)?0:-x);
dp[0][1] = nums[0] + ((nums[0]%2==0)?0:-x);
for(int i=1;i<n;i++)
{
if(nums[i]%2==1)
{
dp[i][0] = max(dp[i-1][0] + nums[i] , dp[i-1][1] + nums[i] - x);
dp[i][1] = dp[i-1][1];
}
else if(nums[i]%2==0)
{
dp[i][0] = dp[i-1][0];
dp[i][1] = max(dp[i-1][1] + nums[i] , dp[i-1][0] + nums[i] - x);
}
}
return max( dp[n-1][0] , dp[n-1][1]);
}
};