31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

58ken the first resident got (he should have received a token with number 1). The third linecontains the number of token the second resident received, etc.Output the minimal number of days, necessary to exchanging tokens to the firstline of the output file.247. Cakes. There are N kinds of cakes of in the confectionery. The amount ofcakes of each kind is limited. The client wants to buy exactly K – we will call it thepurchase. In the purchase there can be several cakes of the same kind (of course, notmore than there are cakes of that kind in the confectionery), some kinds of cakes maynot be included into purchase. Two purchases are different, if there exist at least onekind of cakes where the amount of this kind of cakes in the two purchases differs.Task. Write a program to find all possible different purchases of the cakes.Input. The first line of the input file contains one integer K (1≤K≤30), which is thenumber of cakes in the purchase. In the second line there is written one integer N(1≤N≤30), the number of different kinds of cakes in the confectionery. It is assumedthat all kinds of cakes are numerated from 1 to N.The remaining N lines contain one number per line, indicating how many cakes ofappropriate kind there are in the confectionery, that is, in the first of the remaininglines there is written number of cakes of the first kind, in the second line there iswritten number of cakes of the second kind and etc.In the input data K and N will se such that given run time limit will be enough togenerate ALL sets of N kinds of cakes having size K.Output the amount of possible different purchases P to the first line of the output file.Further there should be P lines, indicating purchases, one line per purchase. Eachline should contain N numbers separated by spaces and indicating how many cakes ofcorresponding kind there are in the purchase (if the purchase does not contain cakesof some kind, 0 must be written).If K cakes can not be bought in any possible way, then 0 must be written in the first(and the only) line of the output file.ExampleInput Output Comments3 3Three cakes (K=3) compound the purchase; There2 0 3 two kinds of cakes in the confectionery (N=2): there are2 1 2 2 cakes are of the first kind and 10 cakes of the second10 2 1 kind.3 different purchases are possible:• 3 cakes of the second kind• 1 cake of the first kind and 2 cakes of thesecond kind• 2 cakes of the first kind and 1 cake of thesecond kind.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!