Book of programming problems

Contains advanced programming problems for schools, colleges and problem-hungry inidividuals

Given prices for post stamps, calculate how much money should be spent to create M unique stamp collections
Complexity (1-100): 20
A new philately club is open, and M philatelists are striving to become its members. At each meeting, the club takes only one member on. In order to become a member, a philatelist must demonstrate that his or her collection of stamps does not contain the same stamp twice and is different from collections of other members. Each philatelist therefore buys a collection of stamps, trying to spend as little money as possible, at the post stamp shop, offering N kinds of stamps (3≤N≤10000) priced x1,x2,...,xn respectively (3≤xi≤10000, i=1 .. N).

For example, if the shop offers 5 kinds of stamps which cost 3, 4, 6, 10, 15, the philatelists will buy them in the following order:

PhilatelistStamps boughtMoney spent
113
224
336
41 and 23+4
51 and 33+6
6410
72 and 34+6
81,2, and 33+4+6
91 and 43+10
102 and 44+10
. . .

Write a program which, based on stamp prices, would calculate the minimum amount of money each philatelist should spend to become a philately club member.

The input data should be read from a text file, containing numbers in separate lines in the following order: the first line id N, the second is M, the next N lines contain stamp prices in ascending order. The output should contain amount of money for each of M philatelists, in ascending order.

Note: All numbers are natural, N M2N-1, M15000. The program is allowed to run no longer than 3 seconds.
Self-tests: self-test 1, self-test 2
Solution:solution.pas
There are no posts in this topic.

Post Reply

Book of programming problems is powered by UseBB 1 Forum Software | Contact Admin