您的位置:首页 > 其它

货币系统(背包)

2018-03-07 22:17 169 查看



货币系统


Problem Description

给你一个n种面值的货币系统,求组成面值为m的货币有多少种方案。


Input

输入有多组数据,每组数据第一行:n,m的值,后面n行为每种货币的面值。


Output

对于每组数据输出组成面值为m的货币的方案数。


Sample Input

3 10
1
2
5



Sample Output

10

#include<bits/stdc++.h>
using namespace std;
int v,n,p,i,j;
int f[1001];
int main()
{
cin >> v >> n;
f[0] = 1;
for(i = 1;i <= v;i ++){
cin >> p;
for(j = p;j <= n;j ++)
f[j] += f[j-p];
}
cout << f
;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: