Ultraviolet A 357 Let Me Count The Ways (01 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: it is the same as uva674, but the upper limit is different. Pay attention to the output.

# Include <stdio. h> # include <string. h> const int N = 30005; const int val [5] = {1, 5, 10, 25, 50}; long cnt [N]; void Init () {memset (cnt, 0, sizeof (cnt); cnt [0] = 1; for (int I = 0; I <5; I ++) {for (int j = val [I]; j <N; j ++) cnt [j] + = cnt [j-val [I] ;}} int main () {Init (); int n; while (scanf ("% d", & n) = 1) {if (cnt [n] <= 1) printf ("There is only 1 way to produce % d cents change. \ n ", n); else printf (" There are % lld ways to produce % d cents change. \ n ", cnt [n], n);} return 0 ;}

 


Related Article

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.