Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer in C++ Suppose you are trying to bind many books together (for whatever reason you can think of). The books may consist of

Please answer in C++ Suppose you are trying to bind many books together (for whatever reason you can think of).

The books may consist of a different number of pages. For example, Book A can have 12 pages and Book B can have 500 pages.

Each time you bind two books together the total effort to perform the binding is equal to the number of pages in both books. For example, Binding Book A and Book B will require 512 units of effort.

Write a program that takes in one line of input. The line of input will be the number of pages for each book separated by commas.

Your program must output theminimum units of effortrequired to bind all the books together.

Input: 100,12,6,40

Output: 234

NB: The best way to bind these books is to firstly bind 12 with 6 which costs18units of effort. We now have books of sizes {100, 18, 40}. We then can bind 18 and 40, which costs58units of effort. We now have books of sizes {100, 58}. And finally we bind 100 and 58 which requires158units of effort. Thus we required 18+58+158 =234units of effort.

Input: 900,46,34,187,23,100,2541,3987

Output: 13692

Input: 187,65,13,4,5,89,13,55,4,99,544

Output: 2480

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago