Projecte.pdf ----> problem = 31 ---- coin sums unlimited backpack computing possible times

Source: Internet
Author: User

Problem 31

In England and the currency is made up of pound, round, and pence, P, and there are eight coins in general circulation:

1 p, 2 p, 5 p, 10 p, 20 p, 50 p, half 1 (100 P) and half 2 (200 P ).

It is possible to make every 2 in the following way:

1 × Jun 1 + 1 × 50 p + 2 × 20 p + 1 × 5 p + 1 × 2 p + 3 × 1 p

How many different ways can be used 2 be made using any number of coins?


 
Import timedef CAL (sum, Count, value): If sum = 200: Count + = 1 returnif sum> 200: returnfor I in range ): sum + = value [I] Cal (sum, Count, value) sum-= value [I] Begin = time. time () num = {100,200,}; num = List (Num) Count = 0cal (0, Count, num) End = time. time () print countprint end-begin

Method 1: Deep Search timeout

 
# Resolution: retrieve the largest coin value from the list each time, and obtain the upper limit of the maximum number of coins. # overlay the number, and use a smaller number. # Def CAL (value, coins): If value = 0 or Len (coins) = 1: return 1 else: coins = sorted (coins) largest = coins [-1] uses = value/largesttotal = 0for I in range (uses + 1): Total + = CAL (value-largest * I, coins [: -1]) return totalprint CAL (200, [100,200,])

Second, greedy and extreme value AC

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.