uva 147 Dollars(完全背包)】的更多相关文章

题目连接:147 - Dollars 题目大意:有11种硬币, 现在输入一个金额, 输出有多少种组成方案. 解题思路:uva 674 的升级版,思路完全一样, 只要处理一下数值就可以了. #include <stdio.h> #include <string.h> const int N = 30005; const int val[11] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000}; long long n,…
首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 细心看完这题后发现还是完全背包,只不过需要对浮点数处理一下.即把所有硬币的面值都乘以100,化为整数,对输入的数据也作同样的处理,然后就是套完全背包的模板了,在输出时还要用格式和精度来卡一卡你……一开始我没想到用printf可以的,于是百度了cout的输出格式控制,…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 147 - Dollars Time limit: 3.000 seconds Dollars New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and…
https://vjudge.net/problem/UVA-147 题意: 换零钱,计算方案数. 思路: 完全背包,UVa674的加强版. #include<iostream> #include<string> #include<cstring> #include<algorithm> using namespace std; + ; , , , , , , , , , , }; long long d[maxn]; int main() { //freo…
题意:一样是求钱的转换方案数,但是这次单位下降到分,但给的是元为单位的,所以是浮点的,但是固定有两位小数. 思路:数据都放大100倍来计算,去除精度问题,转成整型时要注意精度.即使给的是0.02,乘以100后的结果不一定是2,而是2左右,所以再加上一个很小的数再转即可,比如0.0001: #include <iostream> #include <cstdio> #define LL long long using namespace std; ; , , , , , , , ,…
题目大意:给出五种硬币,价值分别为 1,5,10,25,50,.当给出一个价值时,求出能够组合的种数(每种硬币可以用无限次). 思路:完全背包, dp[i][j]表示总数 i 能够被表示的种数.状态转移方程为 dp[i][j] = dp[i-k*v[j]][j-1] (k = 0,1,2,3...). C++ 代码如下: #include<iostream> #include<cstdio> #include<algorithm> #include<cmath&g…
/* * UVA_147.cpp * * Created on: 2013年10月12日 * Author: Administrator */ #include <iostream> #include <cstdio> using namespace std; const int maxn = 6005; int b[11] = {1,2,4,10,20,40,100,200,400,1000,2000}; long long a[maxn]; int main(){ double…
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使得装入背包的总价值最大?*01 背包 *01 背包特点: 给定 n 种物品和一个背包 ( 每个物品只能选取一个).物品 i 的重量是w[i],其价值为v[i],背包的容量为C.应该如何选择装入背包中的物品,使得装入背包中的物品的总价值最大?*状态: dp[i][j] 表示在只能从 1-i 个物品中选…
#include<bits/stdc++.h> using namespace std; int main() { unsigned ]; memset(dp,,sizeof(dp)); dp[]=; ;i<=;i++) ;j++) dp[j]=dp[j]+dp[j-i]; int n; while((scanf("%d",&n))!=EOF) { printf("%I64d\n",dp[n]); } ; ; } 这两道题基本思路是一样的,…
UVA 10306 e-Coins(全然背包: 二维限制条件) option=com_onlinejudge&Itemid=8&page=show_problem&problem=1247">http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1247 题意: 对于每一个例子.先给定两个数n,m,分别表示有…
link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 和完全背包一样的思想. 有两个trick: 浮点数转化成整数的时候,注意精度. 因为题目中说了都是5的倍数,所以可以都除以5. 没了. #include <iostream> #include <cstdio> #include <cstdlib&g…
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=565 题意很好理解,普通的01背包,dp[i - 1][j]表示在前i - 1件物品中选取若干物品放入容量为j背包所得到的最大的价值,dp[i - 1][j - w[i]] + v[i]表示前i - 1件物品中选取若干物品放入容量为j - w[i]背包所得到的最大的价值加上第i件物…
People in Cubeland use cubic coins. Not only the unit of currency iscalled a cube but also the coins are shaped like cubes and their valuesare cubes. Coins with values of all cubic numbers up to 9261(= 213),i.e., coins with the denominations of 1, 8,…
Problem F Equating Equations Input: standard input Output: standard output Time Limit: 6 seconds Memory Limit: 32 MB Read equations with up to 16 terms and + and – operators (not unary) and reorder the terms (but not the operators) so that the equati…
//路径记录方法:若是dp[j-value[i]]+value[i]>dp[j]说明拿了这个东西,标志为1, //for循环标志,发现是1,就打印出来,并把背包的容量减少,再在次容量中寻找标志: #include <iostream> #include <cstring> #include <algorithm> using namespace std; ],dp[],s[][]; int main() { int n,m; while(cin>>m)…
DescriptionCD You have a long drive by car ahead. You have a tape recorder, but unfortunately your best music is on CDs. You need to have it on tapes so the problem to solve is: you have a tape N minutes long. How to choose tracks from CD to get most…
 Dollars New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing…
这里就是01背包多了一维物品个数罢了 记得不能重复所以有一层循环顺序要倒着来 边界f[0][0] = 1 #include<cstdio> #include<vector> #include<cstring> #define REP(i, a, b) for(int i = (a); i < (b); i++) using namespace std; const int MAXN = 1121; bool is_prime[MAXN]; vector<in…
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #include<algorithm> #define N 1010 using namespace std; int dp[N], path[N][N], w[N]; int main() { int v, n; while(~scanf("%d", &v)) { sca…
一个简单的dp   面值是5的倍数  将面值都除5   因为输出问题wa .... #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; long long f[6020]; int coin[] = {1,2,4,10,20,40,100,200,400,1000,2000}; void dp(int n) { m…
// 集训最终開始了.来到水题先 #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int a[23]; int d[23][100000]; int flag[23]; int W,n; void init(){ cin >> n; for (int i=1;i<=n;i++) cin >…
1.hdu 2126 Buy the souvenirs 题意:给出若干个纪念品的价格,求在能购买的纪念品的数目最大的情况下的购买方案. 思路:01背包+记录方案. #include<iostream> #include<cstdio> #include<cstring> using namespace std; ; ; int cnt[maxw]; int dp[maxw]; int p[maxn]; int main() { int t; scanf("%…
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) ACM总结(fennec) 其实在北京比赛完的时候,我就想写了,不过还是早了点,直到上海比赛结束,大家的心中都不是太好受.郭老师有句话:你们这样做也是对的,不成功就成仁.让我的心也能安慰了不少. 我是从大一下学期开始接触ACM的,那时候我们学校才刚刚起步,siyee,wjiang师兄可以说是我的领路人了…
111 - History Grading LCS 103 - Stacking Boxes 最多能叠多少个box DAG最长路 10405 - Longest Common Subsequence LCS 674 - Coin Change 全然背包求方案数 10003  - Cutting Sticks 区间DP dp[l][r]代表分割l到r的最小费用 116 - Unidirectional TSP 简单递推 输出字典序最小解 从后往前推 10131 - Is Bigger Smarte…
UVA题解三 UVA 127 题目描述:\(52\)张扑克牌排成一列,如果一张牌的花色或者数字与左边第一列的最上面的牌相同,则将这张牌移到左边第一列的最上面,如果一张牌的花色或者数字与左边第三列的最上面的牌相同,则将这张牌移到左边第三列的最上面.只有最上面的牌可以移动,如果同时有多张牌可以移动,则先移动最左边的牌,若某张牌可以移到左边第三列的上面,则优先移到左边第三列.若某个时刻某一列为空,则那一列后面的列往前移动.求最后还剩多少列,以及每一列有多少张牌. solution 直接栈模拟.因为每张…
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes…
10192 最长公共子序列 http://uva.onlinejudge.org/index.php?option=com_onlinejudge& Itemid=8&page=show_problem&category=114&problem=1133&mosmsg= Submission+received+with+ID+13297616 */ #include <cstdio> #include <string.h> #include&…
题目链接:https://uva.onlinejudge.org/external/125/12563.pdf 题意:n首歌,每首歌的长度给出,还剩 t 秒钟,由于KTV不会在一首歌没有唱完的情况下切歌,求在总曲目尽量多的情况下,唱的最久. 分析: 刚开始,题意看错了,结果就按01背包模板了,求了在 t 时间下唱的最久,然后再找出唱了几首歌.WA到疯了,最后实在是崩溃啊! 然后,这个题目没做出来,主要还是01背包没弄透彻.可以利用二维 [2][t] 的滚动数组求路径,这里不仅是优化了空间,而且,…
Problem C.Storage Keepers  Background Randy Company has N (1<=N<=100) storages. Company wants some men to keep them safe. Now there are M (1<=M<=30) men asking for the job. Company will choose several from them. Randy Company employs men follo…
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory Limit: 32 MB In ancient days there was a country whose people had very interesting habits. Some of them were lazy, some were very rich, some were very…