【例9.17】货币系统
链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1273
时间限制: 1000 ms 内存限制: 65536 KB
【题目描述】
给你一个n种面值的货币系统,求组成面值为m的货币有多少种方案。
【输入】
第一行为n和m。
【输出】
一行,方案数。
【输入样例】
3 10 //3种面值组成面值为10的方案 1 //面值1 2 //面值2 5 //面值5
【输出样例】
10 //有10种方案
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[1005];
long long f[10005];
int main()
{
int n,V;
cin>>n>>V;
for(int i=1;i<=n;i++)cin>>a[i];
f[0]=1;
for(int i=1;i<=n;i++)
for(int j=a[i];j<=V;j++)
f[j]+=f[j-a[i]];
cout<<f[V]<<endl;
}
来源:https://www.cnblogs.com/EdSheeran/p/7631959.html