UVA 674-Coin Change(DP)

题目链接:点击打开链接

题意 :有5种硬币的面值,分别为 1 ,5 ,10 ,25 ,50 。。 给出n 问用这些面值的硬币有多少种组成n的方式。(每种硬币无限,使用硬币数也无限)

两种做法,母函数比较长,以前也写过就不说了。。

第二种做法是DP 设 dp[i] 为组成i 的种类数,初始化dp[0]=1; (有图有真相 题目中原话 :Note that we count that there is one way of making change for zero cent) dp[i]=dp[i]+dp[i-v[j]] 枚举5种面值。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define maxn 1<<12
#define _ll __int64
#define ll long long
#define INF 0x3f3f3f3f
#define Mod 1000000007
#define pp pair<int,int>
#define ull unsigned long long
using namespace std;
int n,dp[7490];
int v[]={1,5,10,25,50};
void solve()
{
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	for(int i=0;i<5;i++)
		for(int j=v[i];j<=n;j++)
		dp[j]+=dp[j-v[i]];
	printf("%d\n",dp[n]);
}
int main()
{
	while(~scanf("%d",&n))
		solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值