You are given an array of positive numbers of size N and an integer K. You need to partition the array into K continuous segments. For each segment, the sum of its elements needs to be calculated. The segment with the minimum sum is called the bestSegment and the sum of the elements of the bestSegment is called the bestSum. For all possible combinations of partitions of the array when divided into K segments, their bestSum needs to be calculated and the one among them with maximum value needs to be returned. Input Specification: input1: an array of N positive numbers input2: an integer N denoting the length of the array input3: an integer K Output Specification: Return an integer denoting the maximum value of all possible bestsum.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Best Partition
You are given an array of positive numbers of size N and an integer K. You need to partition the array into K
continuous segments. For each segment, the sum of its elements needs to be calculated.
The segment with the minimum sum is called the bestSegment and the sum of the elements of the
bestSegment is called the bestSum.
For all possible combinations of partitions of the array when divided into K segments, their bestSum needs to be
calculated and the one among them with maximum value needs to be returned.
Input Specification:
input1: an array of N positive numbers
input2: an integer N denoting the length of the array
input3: an integer K
Output Specification:
Return an integer denoting the maximum value of all possible bestSum.
Example 1:
input1: (1,2,3,4}
input2: 4
input3: 2
Output: 4
Explanation:
You can partition the given array into 2 continuous segments in the following manner-
• 123 14- the sum of individual segments is (6,4) and the bestSum is 4
• 12134- the sum of individual segments is (3.7) and the bestSum is 3
• 1|234- the sum of individual segments is (1.9) and the bestSum is 1
The maximum value of bestSum among {4,3,1) is 4. So, 4 will be returned as the answer.
Example 2:
input1: (5,6,6,8}
input2: 4
input3: 4
Output: 5
Explanation:
You can partition the given array into 4 continuous segments only in one way-
5161618-The sum of individual segments is (5,6,6,8) and the bestSum is 5.
Since the only value of bestSum is 5, it will be returned as the answer.
1 #include<stdio.h>
2 #include<string.h>
3 #include<string>
4
5 using namespace std;
6 // Read only region start
7
8 int BestPartition (int input1[], int input2, int input3)
9
{
10
11
12
13
14 }
15
16
// Read only region end
// Write code here
//throw "Function BestPartition (int input1[], int input2, int input3) not implemented. ";
Transcribed Image Text:Best Partition You are given an array of positive numbers of size N and an integer K. You need to partition the array into K continuous segments. For each segment, the sum of its elements needs to be calculated. The segment with the minimum sum is called the bestSegment and the sum of the elements of the bestSegment is called the bestSum. For all possible combinations of partitions of the array when divided into K segments, their bestSum needs to be calculated and the one among them with maximum value needs to be returned. Input Specification: input1: an array of N positive numbers input2: an integer N denoting the length of the array input3: an integer K Output Specification: Return an integer denoting the maximum value of all possible bestSum. Example 1: input1: (1,2,3,4} input2: 4 input3: 2 Output: 4 Explanation: You can partition the given array into 2 continuous segments in the following manner- • 123 14- the sum of individual segments is (6,4) and the bestSum is 4 • 12134- the sum of individual segments is (3.7) and the bestSum is 3 • 1|234- the sum of individual segments is (1.9) and the bestSum is 1 The maximum value of bestSum among {4,3,1) is 4. So, 4 will be returned as the answer. Example 2: input1: (5,6,6,8} input2: 4 input3: 4 Output: 5 Explanation: You can partition the given array into 4 continuous segments only in one way- 5161618-The sum of individual segments is (5,6,6,8) and the bestSum is 5. Since the only value of bestSum is 5, it will be returned as the answer. 1 #include<stdio.h> 2 #include<string.h> 3 #include<string> 4 5 using namespace std; 6 // Read only region start 7 8 int BestPartition (int input1[], int input2, int input3) 9 { 10 11 12 13 14 } 15 16 // Read only region end // Write code here //throw "Function BestPartition (int input1[], int input2, int input3) not implemented. ";
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education