← 返回 openai 的题目列表Maximize Rice Units Taken Without Emptying Piles Using DP
类型:online_judge
openai
Use dynamic programming to solve the following problem: You have an integer array where each element represents the initial units of rice in a pile. You can start from any pile, and at each step, choose to take any number of rice units from the current pile, but not more than the remaining units in that pile. Simultaneously, you may choose to move to an adjacent pile or end your action. The goal is to maximize the total units of rice taken without emptying any pile completely. Given an integer array piles representing the amount of rice in each pile, find the maximum rice units that can be taken. Example:
Input: piles = [3, 4, 5, 1, 2]
Output: 9
Constraints:
1 <= piles.length <= 10^4
1 <= piles[i] <= 1000
Example
Input
3 4 5 1 2