# Dynamic Programming, Part 2–1

Example of Dynamic Programming, Part 1

This is a note I took while taking Avik Das’ Dynamic Programming course at Linkedin Learning. His course is awesome and I highly recommend it!

# Flowerbox problem

Goal: Maximize the total height of all planted flowers.

## Example solution

Fundamental problem

Mathematical form

#include <iostream>

#include <algorithm>using namespace std;

int bed[5] = {3, 10, 3, 1, 2};

int n = 0;int flowerbed(int n)

{

int a = 0;

int b = 0;

int temp;

for (int i=0; i<=n; i++) {

temp = a;

a = b;

b = max(temp + bed[i], b);

}

return b;

}int main()

{

cin >> n;

cout << flowerbed(n-1) << endl;

}