Chapter 9: Dynamic Programming II
Activity 22: Maximizing Profit
In this activity, we will optimize our inventory for sale to maximize our profits. Follow these steps to complete the activity:
- Let's begin by including the following headers:
#include <iostream> #include <vector> using namespace std;
- First, we will define a structure,
Product
, that encapsulates the data associated with each item:struct Product { int quantity; int price; int value; Product(int q, int p, int v) : quantity(q), price(p), value(v) {} };
- Next, we will handle the input in the
main()
function and populate an array of theProduct
type:int main() { int N, budget, capacity; cin >> N >> budget >> capacity; vector<Product> products; &...