货币系统

Problem Description

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

Input

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

Output

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

Sample Input

3 10                          
1                                  
2                                    
5

Sample Output

10 


【思路】求背包方案总数
【代码】
#include<iostream>
#include<cstdio>
using namespace std;
int a[20];
long long f[20];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    f[0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=a[i];j<=m;j++)
        {
            f[j]=f[j]+f[j-a[i]];//选这个货币或者不选 
        }
    }
    printf("%lld",f[m]);
    return 0;
}


原文地址:https://www.cnblogs.com/zzyh/p/6749478.html