3010. Divide an Array Into Subarrays With Minimum Cost I Easy
1/**
2 * [3010] Divide an Array Into Subarrays With Minimum Cost I
3 *
4 * You are given an array of integers nums of length n.
5 * The cost of an array is the value of its first element. For example, the cost of [1,2,3] is 1 while the cost of [3,4,1] is 3.
6 * You need to divide nums into 3 disjoint contiguous <span data-keyword="subarray-nonempty">subarrays</span>.
7 * Return the minimum possible sum of the cost of these subarrays.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: nums = [1,2,3,12]
12 * Output: 6
13 * Explanation: The best possible way to form 3 subarrays is: [1], [2], and [3,12] at a total cost of 1 + 2 + 3 = 6.
14 * The other possible ways to form 3 subarrays are:
15 * - [1], [2,3], and [12] at a total cost of 1 + 2 + 12 = 15.
16 * - [1,2], [3], and [12] at a total cost of 1 + 3 + 12 = 16.
17 *
18 * <strong class="example">Example 2:
19 *
20 * Input: nums = [5,4,3]
21 * Output: 12
22 * Explanation: The best possible way to form 3 subarrays is: [5], [4], and [3] at a total cost of 5 + 4 + 3 = 12.
23 * It can be shown that 12 is the minimum cost achievable.
24 *
25 * <strong class="example">Example 3:
26 *
27 * Input: nums = [10,3,1,1]
28 * Output: 12
29 * Explanation: The best possible way to form 3 subarrays is: [10,3], [1], and [1] at a total cost of 10 + 1 + 1 = 12.
30 * It can be shown that 12 is the minimum cost achievable.
31 *
32 *
33 * Constraints:
34 *
35 * 3 <= n <= 50
36 * 1 <= nums[i] <= 50
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/
42// discuss: https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-i/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn minimum_cost(nums: Vec<i32>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_3010() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.