zoukankan      html  css  js  c++  java
  • AcWing 1021. 货币系统

    Acwing 1021

    Description

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

    (n≤15), (m≤3000)

    Solution

    完全背包。

    即将(n) 种货币视为有(n) 个物品,每个物品都可以取无限次,求达到(m) 重量的方案数。

    考虑(f[j]) 表示达成(j) 重量的方案数,每新加入一种货币便更新答案

    则转移方程为(f[j] = f[j] + f[j - a[i]] (a[i] ≤ j)).

    初始值(f[0] = 1)注意要开LL

    code

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #include <queue>
    #include <stack>
    #define REP(i, x, y) for(register int i = x; i < y; i++)
    #define rep(i, x, y) for(register int i = x; i <= y; i++)
    #define PER(i, x, y) for(register int i = x; i > y; i--)
    #define per(i, x, y) for(register int i = x; i >= y; i--)
    #define lc (k << 1)
    #define rc (k << 1 | 1)
    using namespace std;
    #define int long long
    const int N = 20;
    const int M = 3005;
    int n, m, f[M], a[N];
    signed main()
    {
        cin >> n >> m;
        rep(i, 1, n)
        {
            cin >> a[i];
        }
        f[0] = 1;
        rep(i, 1, n)
        {
            rep(j, a[i], m)
            {
                f[j] = f[j] + f[j - a[i]];
            }
        }
        cout << f[m];
        return 0;
    }
    
  • 相关阅读:
    django-替代为自定义的User model
    python *args 和 ** kwargs
    MySQL:性能优化
    MySQL:常用的数据模型
    MySQL:存储过程和函数
    MySQL:用户管理
    MySQL:索引
    MySQL:基础知识
    Linux:NFS配置
    Linux:Apache安装与启动
  • 原文地址:https://www.cnblogs.com/pjxpjx/p/14787296.html
Copyright © 2011-2022 走看看