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 theProducttype:int main() { Â Â Â Â int N, budget, capacity; Â Â Â Â cin >> N >> budget >> capacity; Â Â Â Â vector<Product> products; Â &...