AcWing 1023. books full backpack

// number of programs seeking full backpack
 // F [i] [j] just past the i-th selected items, and the total volume of the solution is exactly the set of j
 // F [i] [j] = F [. 1-i] [ J] + F [-I. 1] [* JV. 1] + F [. 1-I] [JV * 2] + ... F [. 1-I] [JV * S] 
 // F [I] [JV] F = [-I. 1] [* JV. 1] + F [. 1-I] [JV * 2] + ... F [. 1-I] [JV * S]
 // so f [i] [j] = f [i-1] [j ] + f [i] [jv]
#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] + f[j - v[i]];
    cout << f[n] << endl;
    return 0;
}

 

 

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11980553.html