Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18240 Accepted Submission(s): 6279
Problem Description
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
Sample Input
11 26
Sample Output
4 13
Author
Lily
Source
http://acm.split.hdu.edu.cn/showproblem.php?pid=2069
此题最坑的地方是没讲换成的硬币数量不能超过100
原题 https://www.bnuoj.com/v3/problem_show.php?pid=17813 是没要求100的 数据量也不一样 方法也不一样
给你这么多钱让你换 有五种(50,25,10,5,1)有多少种方法 1 5 和 5 1算一种
这题有太多的方法了 母函数(解决排列组合问题) dp背包 记忆化搜索
我这里要讲的是暴力 给的是250 明显让你暴力(优化一下)
还有的仁兄直接暴力打表 太可怕了 用搜索打表
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,k,u,sum;
while(scanf("%d",&n)!=EOF)
{
sum=0;
for(i=0; i<=n/50; i++)
{
int g1=n-i*50;
for(j=0; j<=g1/25; j++)
{
int g2=g1-j*25;
for(k=0; k<=g2/10; k++)
{
int g3=g2-k*10;
for(u=0; u<=g3/5; u++)
{
int g4=g3-u*5;
if(i+j+k+u+g4<=100)
sum++;
}
}
}
}
printf("%d\n",sum);
}
return 0;
}