货币系统(方案数)

货币系统(方案数)

![在这里插入图片描述]( https://img-blog.csdnimg.cn/53eac1559dfe430f81fdfb782f5d4ba0.png?x-oss-process=image/watermark ,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUGFuc2XCtw==,size_20,color_FFFFFF,t_70,g_se,x_16)

样例输入:

3 10
1
2
5

样例输出:

10

代码模板:

//背包问题求方案数
#include <iostream>

using namespace std;

typedef long long LL;

const int M = 3010;

int n, m;
LL f[M];

int main()
{
    cin >> n >> m;

    f[0] = 1;
    for (int i = 0; i < n; i ++ )
    {
        int v;
        cin >> v;
        for (int j = v; j <= m; j ++ )
            f[j] += f[j - v];
    }

    cout << f[m] << endl;

    return 0;
}


 

posted @ 2022-03-22 14:20  panse·  阅读(41)  评论(0)    收藏  举报