本文共 1919 字,大约阅读时间需要 6 分钟。
1、
2、题目大意:
给定11种面值分别为$100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins的钱,现在给定一个钱数,求出可以组成的种类数,类似于uva 674,不过此题的精度太强了,纠结。。。
int n=(int)(nn*100+0.5);,注意用long long ,种类数可能非常大
用dp[i][j]表示用前i种硬币,组成j分的种类数,
状态转移方程:dp[i][j]+=DP(i-1,j-k*d[i]);
3、题目:
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 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 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.
0.202.000.00
0.20 4 2.00 293
4、AC代码:
#include#define N 30005#include #define ll long longint d[11]= {5,10,20,50,100,200,500,1000,2000,5000,10000};ll dp[15][N];//dp[i][j]表示用前i种硬币,组成j分的种类数ll DP(ll i,ll j){ //printf("%d %d %d\n",i,j,dp[i][j]); if(dp[i][j]!=-1) return dp[i][j]; dp[i][j]=0; for(int k=0;j-k*d[i]>=0;k++) { dp[i][j]+=DP(i-1,j-k*d[i]); } return dp[i][j];}int main(){ double nn; memset(dp,-1,sizeof(dp));//赋值一次即可,否则可能会超时 while(scanf("%lf",&nn)!=EOF) { if(nn==0.00) break; int n=(int)(nn*100+0.5);//注意精度 for(ll i=0; i<=n; i++) dp[0][i]=1; printf("%6.2f%17lld\n",nn,DP(10,n)); } return 0;}/*0.202.000.00 0.20 4 2.00 293*/
转载地址:http://vqddi.baihongyu.com/