P1474 货币系统 Money Systems

题目描述

母牛们不但创建了它们自己的政府而且选择了建立了自己的货币系统。由于它们特殊的思考方式,它们对货币的数值感到好奇。

传统地,一个货币系统是由1,5,10,20 或 25,50, 和 100的单位面值组成的。

母牛想知道有多少种不同的方法来用货币系统中的货币来构造一个确定的数值。

举例来说, 使用一个货币系统 {1,2,5,10,...}产生 18单位面值的一些可能的方法是:18x1, 9x2, 8x2+2x1, 3x5+2+1,等等其它。 写一个程序来计算有多少种方法用给定的货币系统来构造一定数量的面值。保证总数将会适合long long (C/C++) 和 Int64 (Free Pascal),即在0 到2^63-1之间。

输入输出格式

输入格式:

 

货币系统中货币的种类数目是 V (1<=V<=25)。要构造的数量钱是 N (1<= N<=10,000)。

第一行: 二个整数,V 和 N 。

第二行: 可用的货币的面值 。

输出格式:

 

输出格式:

 

单独的一行包含那个可能的用这v种硬币凑足n单位货币的方案数。

输入输出样例

输入样例#1: 复制
3 10
1 2 5
输出样例#1: 复制
10

说明

翻译来自NOCOW

USACO 2.3

漫威系列四:

今天我的皮肤是蝙蝠侠;

今天我的名字是闪电侠。

又遇到了最折磨人的dp。

我刚开始看这个题目,,,不觉得是动规呢。。。

思路是完全背包。

奈何我解释不了。

ac代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring>
 6 using namespace std;
 7 
 8 int n,x,v[26];
 9 long long f[10002];
10 
11 int main()
12 {
13     scanf("%d%d",&n,&x);
14     for(int i=1;i<=n;++i)    
15         scanf("%d",&v[i]);
16     f[0]=1;     
17     for(int i=1;i<=n;++i)
18         for(int j=v[i];j<=x;j++)
19             f[j]+=f[j-v[i]];
20     printf("%lld",f[x]);
21     return 0;
22 }
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<cstring> 
 6 using namespace std;
 7 
 8 long long f[20000]; 
 9 int n,x,q;
10   
11 int main()
12 {    
13     scanf("%d%d",&n,&x);
14     f[0]=1;
15     for(int i=1;i<=n;i++)
16     {
17         scanf("%d",&q);
18         for(int j=q;j<=x;j++)
19         f[j] += f[j-q];
20     }
21     printf("%lld",f[x]);
22     return 0;
23 }

代码还是参考的gryz某位大佬的blog:

https://www.cnblogs.com/mjtcn/p/6874732.html

猜你喜欢

转载自www.cnblogs.com/Mary-Sue/p/9133367.html