6931. 访问数组中的位置使分数最大

6931. 访问数组中的位置使分数最大_第1张图片

   分奇偶讨论  dp[i][j] 1---i 中以j(偶数 or 奇数)结尾的最大值

class Solution {
public:
    long long maxScore(vector& nums, int x) {
        int n = nums.size();
        
        vector> dp(n,vector (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

 

你可能感兴趣的:(算法,leetcode,动态规划)