CLRs 16th Chapter Study Questions

Source: Internet
Author: User
Study Questions 16-1

First of all, the coin change problem has the best sub-structure, we have to find the optimal solution of the problem of n n cents, and know that the optimal solution uses a C-penny coin, set the optimal solution using K K coins, we think the best solution to solve this problem is to use the problem n−c n-c cents and used k−1 k-1 A coin. Obviously, solving n−c n-c cents and using k−1 k-1 coins using n-N cents of the solution, if we have less than k−1 k-1 a coin to find n−c n-c cents problem, then we can use this solution instead of n-N cents problem, and less than K K coins, which with the most Excellent solution contradiction.
a) Q=⌊n/25⌋q = \lfloor n/25\rfloor, remaining n′=n mod n ' = n\ mod\ 25 cents, D=⌊n′/10⌋d=\lfloor n '/10\rfloor, remaining D′=n′mod 10,k=d′ /5 d ' =n ' \mod\ 10,k=d '/5, the remaining K′=d′mod 5 K ' =d ' \ mod\ 5, the rest are all 1 1 cents coins, the summary is to choose the largest change each time, if the denomination is larger than the selected banknotes, you can redeem, otherwise choose smaller change, and so on.

b) prove slightly.

c) There are now 30 30 cents, the denomination of the coin is 25,10,1 25,10,1, the solution obtained by the greedy algorithm is 25,1,1,1,1,1 25,1,1,1,1,1, that is, 6 6 coins, which should actually be

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.