Brief Description:
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.
n元找零,求找法。
Analyse:
背包问题
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#define INF 0x7fffffff
#define SUP 0x80000000
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
const int N=10007;
int c[]={0,1,5,10,25,50};
int dp[N];
inline int MAX(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n;
while(scanf("%d",&n)==1)
{
dp[0]=1;
for(int i=1;i<=n;i++) dp[i]=0;
for(int i=1;i<=5;i++)
{
for(int j=c[i];j<=n;j++)
{
dp[j]+=dp[j-c[i]];
}
}
printf("%d\n",dp[n]);
}
return 0;
}