Competitive Programming Beginner Topics Part 4

Boohoo ~ It’s dp time

1. Introduction to Dynamic Programming


Dynamic programming (abbreviated DP), is an approach to solving problems through ‘clever bruteforce’. It is a technique that combines the correctness of complete search and the efficiency of greedy algorithms. Dynamic programming can be applied if the problem can be divided into overlapping subproblems that can be solved independently.

There are two common uses for dynamic programming:

  • Finding an optimal solution: You want to find a solution that is as large as possible or as small as possible.
  • Counting the number of solutions: You want to calculate the total number of possible solutions.

If you’re following this series, DP could be quite a jump in terms of difficulty and thinking of approaches to problems. Take your time to assimilate the contents of the following links/guides and understand what’s going on. The internet has a lot more resources to explore if you’re stuck.

The links that follow are good to start with, but you will most probably have to revisit and re-read them multiple times as you struggle through the components that follow.

Reading material:

Problems


Note: Solutions to AtCoder DP contest problems can be found here.

2. Coin change

Reading material:

Problems


Note: Solutions to CSES DP section problems can be found here.

3. Maximum sum subarray (Kadane’s algorithm)

Reading material:

Problems

4. Knapsack

Reading material:

Problems


Challenging problems

5. Longest Common Subsequence & Edit distance

Reading material:

Problems

6. Longest Increasing Subsequence

The dp approach is $\mathcal{O}(n^2)$ and helps build intuition and understanding. However, since there exists methods to solve it in O(nlogn), often you will not be able to use this approach.

Reading material:

Problems

7. Grid DP

Reading material:

Problems

8. Matrix Chain Multiplication style DP

Reading material:

Problems

Practice

Recommended:

Some easy problems

Knapsack

Segments and subsequences

Combinatorics and number theory

Misc.

If you’re following the series, the motivation here is to make yourself familiar with the topics mentioned above. You may find some of these problems fairly difficult, so the idea is to put those problems on hold but surely come back later to solve them. For now, try to attempt at least the first two problems of each sub topic.

Competitive Programming Beginner Topics Part 5