买书

https://www.acwing.com/problem/content/280/

\(完全背包变式\)

01背包变式

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define VIT vector<int>
#define x first
#define y second
#define inf 0x3f3f3f3f
const int N = 1010; 
int f[N];
int a[] = {0, 10, 20, 50, 100};
 
int main() {
    IO;
    int n;
    cin >> n;
    f[0] = 1;
    for (int i = 1; i <= 4; ++i) 
        for (int j = 0; j <= n; ++j) 
            if (j >= a[i]) f[j] += f[j - a[i]];
            
    cout << f[n] << '\n';
    return 0;
}

posted @ 2021-04-12 21:41  phr2000  阅读(34)  评论(0编辑  收藏  举报