UVa 674 Coin Change(完全背包)

https://vjudge.net/problem/UVA-674

题意:

计算兑换零钱的方法共有几种。

思路:

完全背包基础题。

 1 #include<iostream>
 2 #include<string>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6
 7 int d[7500];
 8 int a[5] = { 1, 5, 10, 25, 50 };
 9
10 int main()
11 {
12     //freopen("D:\\txt.txt", "r", stdin);
13     int s;
14     while (cin >> s)
15     {
16         memset(d, 0, sizeof(d));
17         d[0] = 1;
18         for (int i = 0; i < 5; i++)
19         {
20             for (int j = a[i]; j <= s; j++)
21                 d[j] += d[j - a[i]];
22         }
23         cout << d[s] << endl;
24     }
25     return 0;
26 }
时间: 2024-11-10 01:05:38

UVa 674 Coin Change(完全背包)的相关文章

uva 674 Coin Change 经典dp入门

Coin Change Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVA 674 Appoint description: Description Download as PDF Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to m

UVa 674 Coin Change (经典DP)

Coin Change Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu 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

UVA 674 Coin Change 硬币转换(完全背包,常规)

题意:有5种硬币,个数无限的,组成n元的不同方案有多少种? 思路:常规完全背包.重点在dp[0]=1,dp[j]中记录的是组成 j 元的方案数.状态转移方程dp[j+coin[i]]+=dp[j]. 1 #include <bits/stdc++.h> 2 using namespace std; 3 int coin[]={1, 5, 10, 25, 50}; 4 int dp[10000], n; 5 6 int cal() 7 { 8 if(!n) return 1; 9 memset(

uva 674 Coin Change(类似完全背包)

有点类似完全背包,不过最后的容量必须被充满. dp[i][j]表示在前i个物品中选择容量不超过j的最大价值. 完全背包转移方程:dp[i][j] = max(dp[i-1][j] , dp[i][j-v[i]]+w[i]) 这道题目设数组dp[i][j]表示用前j个硬币组成i的种类个数,转移方程:dp[i][j] = dp[i-1][j]+dp[i][j- a[i]]因为这里求得是解的个数,所以要用加法,完全背包是求某一种情况所以去最大的.(明天实现一下一维数 组) 代码: #include<i

UVA 674 Coin Change

DP,背包的思想. 问 最多7489块钱.有多少种组成方式.面额分别为 1,5,10,25,50: 由于不限制硬币数量,所以完全背包,累加就可以了. #include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<map> #include<stack> #include<iostream

UVA 674 Coin Change (DP)

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 c

UVa 674 Coin Change【记忆化搜索】

题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn.net/keshuai19940722/article/details/11025971 这一篇说的是会有面值的重复问题,还不是很理解 还有就是一个预处理的问题, 看了题解之后再自己写,很习惯的把处理dp数组写到while循环里面,一直tle 后来看到这篇题解 http://www.cnblogs.

uva674 - Coin Change(完全背包)

题目:uva674 - Coin Change(完全背包) 题目大意:给1 5 10 25 50 这5中面值的硬币,然后给出N,问用这些钱组成N的不同方式数目.1 5 和 5 1 表示同一中,顺序不同算相同. 解题思路:完全背包. 状态方程:dp[j] += dp[ j - v[i]]: 代码: #include <cstdio> #include <cstring> const int N = 5; const int maxn = 8000; typedef long long

LightOJ 1231 Coin Change (I) (背包计数模板题)

1231 - Coin Change (I) PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB In a strange shop there are n types of coins of valueA1, A2 ... An.C1, C2,... Cn denote the number of coins of valueA1, A2... An respectively. You have