The maximum benefit of investment - Los Valley P1853

Title Description

The maximum investment benefits P1853

Solution: Full backpack

The only completely different and knapsack problem is that the number of the total amount is to change, so we'll put the total amount in one cycle for updating the Out of the total circulation of the knapsack problem

#include <bits/stdc++.h>

using namespace std;

struct bond{
    int w, c;
};

int main()
{
    bond bo[51];
    int s, n, d, f[100000000];
    cin >> s >> n >> d;
    for(int i=1;i<=d;i++)
        cin >> bo[i].w >> bo[i].c;
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=d;i++)
            for(int j=bo[i].w;j<=s;j++)
                f[j] = max(f[j], f[j-bo[i].w]+bo[i].c);
         s += f[s];
    }
    cout << s;

    return 0;
}
Published 152 original articles · won praise 22 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_38204302/article/details/105202684