← 返回 bytedance 的题目列表Content Clustering
类型:online_judge
TikTok needs to optimally deliver video content to users. There is a sequence of video chunks represented by an array of integers, videoChunks, where each element videoChunks[i] represents a chunk with an associated delivery cost. The task is to partition this sequence into exactly k non-empty groups to minimize the total cost of all the groups. The cost of a group (subarray) is defined as the sum of the costs of its first and last video chunk in that group.\n\nExample:\n\nGiven n = 5, videoChunks = [7, 8, 3, 9, 6], and k = 2. An optimal way is to divide the array into two subarrays: [[7, 8], [3, 9, 6]].\n\nCost of first subarray = 7 + 8 = 15 \nCost of second subarray = 3 + 6 = 9\nThus, the total cost is 15 + 9 = 24. It can be proven that the minimum possible total cost is 24.
Example
Input
7
8 9 8 2 9 9 2
3