813. Largest Sum of Averages Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [813] Largest Sum of Averages
3 *
4 * You are given an integer array nums and an integer k. You can partition the array into at most k non-empty adjacent subarrays. The score of a partition is the sum of the averages of each subarray.
5 * Note that the partition must use every integer in nums, and that the score is not necessarily an integer.
6 * Return the maximum score you can achieve of all the possible partitions. Answers within 10^-6 of the actual answer will be accepted.
7 *  
8 * Example 1:
9 * 
10 * Input: nums = [9,1,2,3,9], k = 3
11 * Output: 20.00000
12 * Explanation: 
13 * The best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.
14 * We could have also partitioned nums into [9, 1], [2], [3, 9], for example.
15 * That partition would lead to a score of 5 + 2 + 6 = 13, which is worse.
16 * 
17 * Example 2:
18 * 
19 * Input: nums = [1,2,3,4,5,6,7], k = 4
20 * Output: 20.50000
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= nums.length <= 100
26 * 	1 <= nums[i] <= 10^4
27 * 	1 <= k <= nums.length
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/largest-sum-of-averages/
33// discuss: https://leetcode.com/problems/largest-sum-of-averages/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn largest_sum_of_averages(nums: Vec<i32>, k: i32) -> f64 {
39        0f64
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_813() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.