Va 674 Coin Change (full backpack)

Source: Internet
Author: User

There are five types of coins with a nominal value of 1, 5, 10, 25, and 50 respectively. Now, we provide the amount and ask how many methods can be used to make up the nominal value. Solution: every coin has an infinite number, so it is a typical full backpack. When I first wrote the paper, I did not consider the duplicate face value. When I typed the table, I calculated the amount one by one, however, cnt [I] + = cnt [I-sex [j] is used, and some composition methods are considered again (this is applicable only for those with less than 50, it will not cause repeated considerations of the nominal value, such as 100. When sex [j] = 25, cnt [100] + = cnt [75], however, the composition method in 75 can be composed of 50 values with a nominal value. Therefore, when sex [j] = 50 is calculated, the calculation is repeated) the correct method is cnt [I] + = low (cnt [I-sex [j]) indicates the composition type of cnt [I-sex [j] with a nominal value less than or equal to sex [j. Written in the code.

# Include <stdio. h> # include <string. h> const int N = 7500; const int sex [] = {1, 5, 10, 25, 50}; int n, cnt [N], t; void Init () {memset (cnt, 0, sizeof (cnt); cnt [0] = 1; for (int I = 0; I <5; I ++) {for (int j = sex [I]; j <N; j ++) cnt [j] + = cnt [j-sex [I] ;}} int main () {Init (); while (scanf ("% d", & n) = 1) {printf ("% d \ n ", cnt [n]);} return 0 ;}

 


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.