UVA 147(子集和问题)
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 does not increase the count. Thus 20c may be made up in 4 ways: 1 20c, 2
10c, 10c+2
5c, and 4
5c.
Input
Input will consist of a series of real numbers no greater than $300.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).
Output
Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 6), followed by the number of ways in which that amount may be made up, right justified in a field of width 17.
Sample input
0.20
2.00
0.00
Sample output
0.20 4
2.00 293 思路:首先离线用dp求出范围内的所有答案。
由于最小货币为5分;所以11种货币以5分为计算单位;
令:
b[i]为第i种货币含5分硬币的数量(0<=i&&i<11);
a[i,j]用前i种货币构成j个5分硬币的方案数(0<=i&&i<11,0<=n&&n<=10000).仅用5分硬币所有可能值为a[1,j]=1;
for(int i=1;i<11;i++)
for(int j=b[i];j<10000;j++){
a[j]+=a[j-b[i]];
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define PI 3.141592653589792128462643383279502
long long a[];
int b[]={,,,,,,,,,,};
int main(){
//#ifdef CDZSC_June
//freopen("in.txt","r",stdin);
//#endif
//std::ios::sync_with_stdio(false);
for(int i=;i<;i++) a[i]=;
for(int i=;i<;i++)
for(int j=b[i];j<;j++){
a[j]+=a[j-b[i]];
}
while(true){
double n;
scanf("%lf",&n);
if(n==0.0) break;
int s=int(n*20.0);
printf("%6.2lf%17lld\n",n,a[s]);
}
return ;
}
UVA 147(子集和问题)的更多相关文章
- hdu 1284 分硬币 && uva 147
#include<bits/stdc++.h> using namespace std; int main() { unsigned ]; memset(dp,,sizeof(dp)); ...
- POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)
首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...
- (DP6.1.2.1)UVA 147 Dollars(子集和问题)
/* * UVA_147.cpp * * Created on: 2013年10月12日 * Author: Administrator */ #include <iostream> #i ...
- uva 147 Dollars
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 147 Dollars(完全背包)
题目连接:147 - Dollars 题目大意:有11种硬币, 现在输入一个金额, 输出有多少种组成方案. 解题思路:uva 674 的升级版,思路完全一样, 只要处理一下数值就可以了. #inclu ...
- uva 147
一个简单的dp 面值是5的倍数 将面值都除5 因为输出问题wa .... #include <iostream> #include <cstring> #includ ...
- UVa 147 Dollars(硬币转换)
题目大意:给出五种硬币,价值分别为 1,5,10,25,50,.当给出一个价值时,求出能够组合的种数(每种硬币可以用无限次). 思路:完全背包, dp[i][j]表示总数 i 能够被表示的种数.状态转 ...
- UVa 147 Dollars(完全背包)
https://vjudge.net/problem/UVA-147 题意: 换零钱,计算方案数. 思路: 完全背包,UVa674的加强版. #include<iostream> #inc ...
随机推荐
- 原生js addclass,hasClass,removeClass,toggleClass的兼容
(function (window) { 'use strict'; // class helper functions from bonzo https://github.com/ded/bonzo ...
- 【BZOJ4817】【SDOI2017】树点涂色 [LCT][线段树]
树点涂色 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description Bob有一棵n个点的有根树,其中1 ...
- bzoj 1202 并查集
首先我们知道若干区间和信息,判断给出信息是否合法,可以用并查集维护,我们用dis[x]表示x到father[x]的距离为多少,即区间father[x]到x的长度,这样我们可以在路径压缩的时候维护dis ...
- Problems with Ribbon/Feign/Zuul retry
原文 https://github.com/spring-cloud/spring-cloud-netflix/issues/1577 I'm using Spring Cloud Camden SR ...
- linux下暴力破解工具hydra【转】
一.简介 Number one of the biggest security holes are passwords, as every password security study shows. ...
- Python3 生成器
生成器(genetor): 1>生成器只有在调用的时候才会生成相应的数据: 2>生成器只记录当前位置,有一个__next__()方法 3>yield可以实现单线程先的并发运算 1.列 ...
- udpserver.pl 和 udpclient.pl
udpserver.pl #!use/bin/perl -w use Socket; #导入Socket库 ,INADDR_ANY);#压入sockaddr_in模式,利用了全局当地压缩地点INADD ...
- 自定义shell开头PS1
vim /etc/profile export PS1="flag:\W \u\$" \h是主机名,并不全,域 \W是当前所在目录名 \u 是当前shell用户名
- 关于eclipase出现的problems during content assist报错问题
解决办法: 把下面箭头指的地方改为上面箭头的指向
- 【Java基础】一些问题
1. HashSet是如何保证数据不重复的: 首先,HashSet添加元素的时候,底层是通过HashMap的put方法来实现的,而添加的元素,则是保存在了hashMap的key里,因为HashMap的 ...