BZOJ1708: [Usaco2007 Oct]Money奶牛的硬币

时间:2023-03-09 17:40:28
BZOJ1708: [Usaco2007 Oct]Money奶牛的硬币

1708: [Usaco2007 Oct]Money奶牛的硬币

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 513  Solved: 329
[Submit][Status]

Description

在创立了她们自己的政权之后,奶牛们决定推广新的货币系统。在强烈的叛逆心理的驱使下,她们准备使用奇怪的面值。在传统的货币系统中,硬币的面值通常是1,5,10,20或25,50,以及100单位的货币,有时为了更方便地交易,会发行面值为2单位的硬币。 奶牛们想知道,对于一个给定的货币系统,如果需要正好凑出一定数量的钱,会有多少种不同的方法。比如说,你手上有无限多个面值为{1,2,5,10,...}的硬币,并且打算凑出18单位货币,那么你有多种方法来达到你的目的:18*1,9*2,8*2+2*1,3*5+2+1,以及其他的未列出的若干方案。 请你写一个程序,帮奶牛们计算一下,如果想用有V (1 <= V <= 25)种面值的硬币,凑出总价值为N(1 <= N <= 10,000)的一堆钱,一共有多少种不同的方法。答案保证不会超出C/C++中的'long long',Pascal中的'Int64',或是Java中的'long'的范围。

Input

* 第1行: 2个用空格隔开的整数:V和N

* 第2..V+1行: 每行1个整数,表示1种硬币面值

Output

* 第1行: 输出1个正整数,表示用这V种面值的硬币,凑出N单位的货币的不同方法总数。

Sample Input

3 10
1
2
5

Sample Output

10

HINT

Source

题解:
无限背包。。。竟然是金组的题。。。
代码:
 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 10000+100
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m;
ll f[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
f[]=;
for(int i=;i<=n;i++)
{
int x=read();
for(int j=x;j<=m;j++)f[j]+=f[j-x];
}
printf("%lld\n",f[m]);
return ;
}