0 votes
by (2 points)
edited

Hello friends. Was interviewed. Zadachu.Sut were asked to solve is the following: the program generates n integers [1 to 10], the program generates a number of K (K may be for example 20); Write program which optimally accommodate the number n in several rows, where the sum of numbers in one line can not exceed the number K. Try to form as small as possible strings.

ANON

4 Answers

0 votes
by (2 points)
edited
1 3 7 8 9 K = 10. In your method is issued 1 3, 7, 8, 9, as many as four lines. Where is optimal.
0 votes
by (2 points)
edited
exactly) I did not remove the thought
0 votes
by (2 points)
edited
Sort by ubyvaniyuDalee string generated by adding the first element of the sorted array. Next in this line adds an element to the end of the sorted array as long as the sum of line items will no longer be K
0 votes
by (2 points)
edited
And is not the same case, the problem was with the K & amp; R even in the first chapter of their book?
Welcome to askiry.com, where you can ask questions and receive answers from other members of the community.
...