Introduction to DP with Bitmasking

Revision en4, by kartik8800, 2021-01-30 21:10:39

Hello Codeforces!

This series of videos are focused on explaining dynamic programming by illustrating the application of DP with bitmasking through the use of selected problems from platforms like Codeforces, Codechef, SPOJ, CSES and Atcoder.

After going through this series, you should find yourself confident in solving problems which require the use of dp and bitmasks and also implementing them in a reasonable amount of time.

I will also live code and submit the solutions to the problem on the coding platform from where the problem comes.

Some Basic elements of Dynamic Programming

Some general ideas and my thoughts about DP to help you get started:

Part 1:
1. What is Divide and Conquer?
2. What is Dynamic Programming?
3. Types of DP problems.

Part 2:
1. What is a DP-state?
2. Characterizing a DP-state.
3. What is a recurrence?
4. Top Down v/s Bottom Up.

Part 3:
1. Directed Acyclic Graph(DAG) Representation of DP solution
2. Visualizing Top-Down and Bottom-Up.
3. Evaluation order for bottom-up codes.
4. Analyzing the space and time complexity for a DP solution(derivation).

You may also want to checkout these video tutorials:
- Beginner Friendly Series on Dynamic Programming
- Dynamic Programming on Trees

About the series

Short video where I talk about the playlist:

What is Bitmasking

I talk about what is bitmasking before we actually start solving problems that use dp with bitmasking.

Illustration: Solving the Job Assignment Problem

Using a simple problem, I will illustrate how to solve and implement problems which use dp+bitmask concepts.
Problem link: statement

Illustration: Travelling Salesman Problem

Another great problem to illustrate bitmask dp.
I will discuss the following:
1. What is the TSP?
2. Brute force solution.
3. Intuition towards an efficient solution.
4. Define a DP state, write a recurrence.
5. How do I implement this? ANS: bitmasking!
6. Analyzing time and space complexities.


Codeforces Problem: Div2E

I'll discuss a problem named Fish that comes from a Codeforces Divison 2 round.
Problem link:

Codechef long Challenge: Medium

The problem comes from Codechef long challenge and is rated MEDIUM by codechef.
Problem link:

CSES: Counting Tilings

The problem comes from CSES problemset and was introduced to the problemset in 2021.
Problem link:

Practice Problems:

If people find this helpful then I will try and add more problems to this list :)


  Rev. Lang. By When Δ Comment
en4 English kartik8800 2021-01-30 21:10:39 306
en3 English kartik8800 2020-08-17 15:23:58 296
en2 English kartik8800 2020-08-15 21:17:37 32
en1 English kartik8800 2020-08-15 21:15:09 3583 Initial revision (published)