Ultraviolet (*)

Source: Internet
Author: User

The questions are as follows:

Stamps 

The Government of Nova mareterrania requires that various legalsponents have stamps attached to them so that the government canderive revenue from them. in terms of recent legislation, each classof document is limited in the number of stamps that may be attached toit. the Government wishes to know how many different stamps, And ofwhat values, they need to print to allow the widest choice of valuesto be made up under these conditions. stamps are always valued inunits of $1.

This has been analyzed by government mathematicians who have derived aformulaN(H,K), WhereHIs the number of stamps that may beattached to a document,KIs the number of denominations of stampsavailable, andNIs the largest attainable value in a continuoussequence starting from $1. For instance, ifH= 3,K= 2 and thedenominations are $1 and $4, we can make all the values from $1 to $6 (as well as $8, $9 and $12 ). however with the same valuesHAndK, But using $1 and $3 stamps we can make all the values from $1 to $7 (as well as $9). This is maximal, soN(3, 2) = 7.

Unfortunately the formula relatingN(H,K)H,KAnd the values ofthe stamps has been lost -- it was published in one of the governmentreports but no-one can remember which one, and of the threeresearchers who started to search for the formula, two died of boredomand the third took a job as a lighthouse keeper because it providedmore social stimulation.

The task has now been passed on to you. You doubt the existence of aformula in the first place so you decide to write a program that, forgiven valuesHAndK, Will determine an optimum set of stamps andthe valueN(H,K).

Input

Input will consist of several lines, each containing a valueHAndK. The file will be terminated by two zeroes (0 0). For technicalreasons the sumHAndKIs limited to 9. (The President lost hislittle finger in a shooting accident and cannot count past 9 ).

Output

Output will consist of a line for each valueHAndKConsisting oftheKStamp values in ascending order right justified in fields 3 characters wide, followed by a space and an arrow (->) And the valueofN(H,K) Right justified in a field 3 characters wide.

Sample Input

 
3 20 0

Sample output

1 3-> 7

Continuous postage. The maximum number of positions of stamps and the maximum number of stamps with different denominations are provided. Assuming that some stamps have been identified, then, the value range of the next stamp should be the maximum value of the face value of the stamp that has been determined + 1 to the maximum value of the continuous postage that can be composed of the stamps that have been determined + 1. if it is smaller, it will repeat the fixed stamp. If it is larger, the maximum value + 1 will not be obtained. In this way, you can restrict the deep search and directly trace back. Use the check function to obtain all the postage that can be composed of all stamps. After a new stamp is determined, the postage that can be composed of the new stamp is updated, and then it is traversed starting from the maximum value of the continuous hot money that can be composed of the previous stamp, it is not until a postage that is not composed of the current stamp, so that the maximum value of the continuous postage is updated to this value-1, continue the deep search.

The AC code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.