11: Greedy algorithm-looking for coins

Source: Internet
Author: User

Problem: Greedy algorithm-looking for coins
Title Description

The existing values are: 1 3 5 10 coins, respectively. Please find N (n<100000000) dollars with a minimum number of coins.
Input
A number that indicates the amount of money to be found
Output
A number that indicates how many coins are needed
Sample input
14
Sample output

3

1#include <stdio.h>2#include <stdlib.h>3 Longk=100000000;4 inta[4]={1,3,5,Ten};5 voidFunintNintMintsum) {6     inti;7     if(sum==N) {8         if(m<k) k=m;9printf"%d\n", k);TenExit0); One     } A     if(sum>n)return; -      for(i=3; i>=0; i--){ -Fun (n,m+1, sum+a[i]); the     } - } - intMain () { -     LongN; +     intm=0, sum=0; -scanf"%d",&n); + Fun (n,m,sum); A      at return 0; -}

 

11: Greedy algorithm-looking for coins

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.