3247. Number of Subsequences with Odd Sum
ArrayMathDynamic ProgrammingCombinatorics
Hints
Hint 1
Define
dp[i][0] as the answer for the subarray [0, i].Hint 2
Similarly define
dp[i][1] as the answer for the subarray [0, i] if we wanted to count even-sum subsequences.Hint 3
If
nums[i] is odd, dp[i][x] = 2i.Hint 4
Otherwise,
dp[i][x] = dp[i - 1][x] * 2.Hint 5
dp[0][1] = 1 if nums[0] is odd, and 0 otherwise.Hint 6
dp[0][0] = 2 if nums[0] is even, and 1 otherwise (since an empty subsequence has an even sum).Preparing judge…