AcWing 1023. 买书(完全背包)

题目链接


题目描述

小明手里有n元钱全部用来买书,书的价格为10元,20元,50元,100元。
问小明有多少种买书方案?(每种书可购买多本)

题目模型

  • 集合表示:f(i,j)
  • 集合含义:所有只从前i个物品中选,且总体积恰好是j的方案的集合
  • 集合属性:Count
  • 集合划分:f[i,j]=f[i-1,j]+f[i,j-v]

题目代码

#include <iostream>

using namespace std;

const int N = 1010;

int n;
int v[4] = {10, 20, 50, 100};
int f[N];

int main()
{
    cin >> n;

    f[0] = 1;
    for (int i = 0; i < 4; i ++ )
        for (int j = v[i]; j <= n; j ++ )
            f[j] += f[j - v[i]];

    cout << f[n] << endl;

    return 0;
}
posted @ 2022-06-04 17:35  esico  阅读(39)  评论(0编辑  收藏  举报