From 884eb1e0c739fad9d949e4c97f7d1fc86034f4ff Mon Sep 17 00:00:00 2001 From: "Zyad M. Ayad" <36793243+Zyad-Ayad@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:02:23 +0200 Subject: [PATCH 1/6] Update intro-to-dp.md --- src/dynamic_programming/intro-to-dp.md | 59 ++++++++++++++++++++------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index 0102581fa..dbced6187 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -130,19 +130,48 @@ That's it. That's the basics of dynamic programming: Don't repeat work you've do One of the tricks to getting better at dynamic programming is to study some of the classic examples. ## Classic Dynamic Programming Problems -- 0-1 Knapsack -- Subset Sum -- Longest Increasing Subsequence -- Counting all possible paths from top left to bottom right corner of a matrix -- Longest Common Subsequence -- Longest Path in a Directed Acyclic Graph (DAG) -- Coin Change -- Longest Palindromic Subsequence -- Rod Cutting -- Edit Distance -- Bitmask Dynamic Programming -- Digit Dynamic Programming -- Dynamic Programming on Trees +
+
0-1 Knapsack
+
given a set of items, each with a weight and a value, and a knapsack with a maximum capacity.
+ +
Subset Sum
+
you are given a set of integers and a target sum. The task is to determine whether there exists a subset of the given set whose elements sum up to the target sum.
+ +
Longest Increasing Subsequence
+
It's a problem that asks for the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order.
+ +
Counting all possible paths from top left to bottom right corner of a matrix
+
solved using dynamic programming or recursion with memoization.
+ +
Longest Common Subsequence
+
Given two sequences (usually strings), the task is to find the length of the longest subsequence that is common to both sequences.
+ +
Longest Path in a Directed Acyclic Graph (DAG)
+
Unlike finding the longest path in a general graph, which is an NP-hard problem, finding the longest path in a DAG can be solved efficiently using dynamic programming.
+ +
Longest Palindromic Subsequence
+
Finding the Longest Palindromic Subsequence (LPS) of a given string.
+ +
Rod Cutting
+
It involves finding the maximum revenue that can be obtained by cutting a rod of length n into smaller pieces and selling them.
+ +
Edit Distance
+
It involves finding the minimum number of operations required to transform one string into another, where the allowed operations are insertion, deletion, or substitution of a single character.
+ +
Bitmask Dynamic Programming
+
Bitmask Dynamic Programming is a technique used to solve combinatorial optimization problems, where the state can be represented compactly using bitmasks.
+ +
Digit Dynamic Programming
+
Digit Dynamic Programming is a technique used to solve problems related to digits of a number.
+ +
Dynamic Programming on Trees
+
a technique used to solve various problems related to trees, such as finding the longest path, computing subtree properties, or counting certain structures within the tree.
+ +
Range Dynamic Programming
+
FinRange Dynamic Programming is a technique used to solve problems where you need to find optimal solutions for subranges within a given range or array.
+ + +
Of course, the most important trick is to practice. @@ -151,3 +180,7 @@ Of course, the most important trick is to practice. * [LeetCode - 118. Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/description/) * [LeetCode - 1025. Divisor Game](https://leetcode.com/problems/divisor-game/description/) +## Dp Contests +* [Atcoder - Educational DP Contest](https://atcoder.jp/contests/dp/tasks) +* [CSES - Dynamic Programming](https://cses.fi/problemset/list/) + From 6c693ede87af4e072572c6999c17f7b82ca0703c Mon Sep 17 00:00:00 2001 From: "Zyad M. Ayad" <36793243+Zyad-Ayad@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:04:49 +0200 Subject: [PATCH 2/6] Update intro-to-dp.md --- src/dynamic_programming/intro-to-dp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index dbced6187..2aa2b791a 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -168,7 +168,7 @@ One of the tricks to getting better at dynamic programming is to study some of t
a technique used to solve various problems related to trees, such as finding the longest path, computing subtree properties, or counting certain structures within the tree.
Range Dynamic Programming
-
FinRange Dynamic Programming is a technique used to solve problems where you need to find optimal solutions for subranges within a given range or array.
+
Range Dynamic Programming is a technique used to solve problems where you need to find optimal solutions for subranges within a given range or array.
From 762f0766719af2ae3d5179377c31bb4fb791d4b0 Mon Sep 17 00:00:00 2001 From: "Zyad M. Ayad" <36793243+Zyad-Ayad@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:40:21 +0200 Subject: [PATCH 3/6] Update intro-to-dp.md Added links to standard problems. --- src/dynamic_programming/intro-to-dp.md | 58 +++++++------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index 2aa2b791a..21b629cd5 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -130,48 +130,22 @@ That's it. That's the basics of dynamic programming: Don't repeat work you've do One of the tricks to getting better at dynamic programming is to study some of the classic examples. ## Classic Dynamic Programming Problems -
-
0-1 Knapsack
-
given a set of items, each with a weight and a value, and a knapsack with a maximum capacity.
- -
Subset Sum
-
you are given a set of integers and a target sum. The task is to determine whether there exists a subset of the given set whose elements sum up to the target sum.
- -
Longest Increasing Subsequence
-
It's a problem that asks for the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order.
- -
Counting all possible paths from top left to bottom right corner of a matrix
-
solved using dynamic programming or recursion with memoization.
- -
Longest Common Subsequence
-
Given two sequences (usually strings), the task is to find the length of the longest subsequence that is common to both sequences.
- -
Longest Path in a Directed Acyclic Graph (DAG)
-
Unlike finding the longest path in a general graph, which is an NP-hard problem, finding the longest path in a DAG can be solved efficiently using dynamic programming.
- -
Longest Palindromic Subsequence
-
Finding the Longest Palindromic Subsequence (LPS) of a given string.
- -
Rod Cutting
-
It involves finding the maximum revenue that can be obtained by cutting a rod of length n into smaller pieces and selling them.
- -
Edit Distance
-
It involves finding the minimum number of operations required to transform one string into another, where the allowed operations are insertion, deletion, or substitution of a single character.
- -
Bitmask Dynamic Programming
-
Bitmask Dynamic Programming is a technique used to solve combinatorial optimization problems, where the state can be represented compactly using bitmasks.
- -
Digit Dynamic Programming
-
Digit Dynamic Programming is a technique used to solve problems related to digits of a number.
- -
Dynamic Programming on Trees
-
a technique used to solve various problems related to trees, such as finding the longest path, computing subtree properties, or counting certain structures within the tree.
- -
Range Dynamic Programming
-
Range Dynamic Programming is a technique used to solve problems where you need to find optimal solutions for subranges within a given range or array.
- - -
+| Name | Description | Example Poblems | +| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- | +| 0-1 Knapsack | 0-1 Knapsack | given a set of items, each with a weight and a value, and a knapsack with a maximum capacity. | [D - Knapsack 1 (](https://atcoder.jp/contests/dp/tasks/dp_d)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_d) | +| 0-1 Knapsack | +| Subset Sum | you are given a set of integers and a target sum. The task is to determine whether there exists a subset of the given set whose elements sum up to the target sum. | | +| Longest Increasing Subsequence | It's a problem that asks for the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. | [Longest Increasing Subsequence - LeetCode](https://leetcode.com/problems/longest-increasing-subsequence/description/) | +| Counting all possible paths in a matrix. | Solved using dynamic programming or recursion with memoization. | [Unique Paths - LeetCode](https://leetcode.com/problems/unique-paths/description/) | +| Longest Common Subsequence | Given two sequences (usually strings), the task is to find the length of the longest subsequence that is common to both sequences. | [F - LCS (](https://atcoder.jp/contests/dp/tasks/dp_f)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_f) | +| Longest Path in a Directed Acyclic Graph (DAG) | Unlike finding the longest path in a general graph, which is an NP-hard problem, finding the longest path in a DAG can be solved efficiently using dynamic programming. | [G - Longest Path (](https://atcoder.jp/contests/dp/tasks/dp_g)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_g) | +| Longest Palindromic Subsequence | Finding the Longest Palindromic Subsequence (LPS) of a given string. | [Longest Palindromic Subsequence - LeetCode](https://leetcode.com/problems/longest-palindromic-subsequence/description/) | +| Rod Cutting | It involves finding the maximum revenue that can be obtained by cutting a rod of length n into smaller pieces and selling them. | | +| Edit Distance | It involves finding the minimum number of operations required to transform one string into another, where the allowed operations are insertion, deletion, or substitution of a single character. | [CSES - Edit Distance](https://cses.fi/problemset/task/1639) | +| Bitmask Dynamic Programming | Bitmask Dynamic Programming is a technique used to solve combinatorial optimization problems, where the state can be represented compactly using bitmasks. | [Problem - F - Codeforces](https://codeforces.com/contest/1043/problem/F) | +| Digit Dynamic Programming | Digit Dynamic Programming is a technique used to solve problems related to digits of a number. | [SPOJ.com](http://SPOJ.com) [- Problem PR003004](https://www.spoj.com/problems/PR003004/) | +| Dynamic Programming on Trees | A technique used to solve various problems related to trees, such as finding the longest path, computing subtree properties, or counting certain structures within the tree. | [P - Independent Set (](https://atcoder.jp/contests/dp/tasks/dp_p)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_p) | +| Range Dynamic Programming | Range Dynamic Programming is a technique used to solve problems where you need to find optimal solutions for subranges within a given range or array. | | Of course, the most important trick is to practice. From fa03985674436f18d4ff96644dcde401820bc0b4 Mon Sep 17 00:00:00 2001 From: "Zyad M. Ayad" <36793243+Zyad-Ayad@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:41:36 +0200 Subject: [PATCH 4/6] Update intro-to-dp.md --- src/dynamic_programming/intro-to-dp.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index 21b629cd5..eb3302a93 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -133,7 +133,6 @@ One of the tricks to getting better at dynamic programming is to study some of t | Name | Description | Example Poblems | | ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- | | 0-1 Knapsack | 0-1 Knapsack | given a set of items, each with a weight and a value, and a knapsack with a maximum capacity. | [D - Knapsack 1 (](https://atcoder.jp/contests/dp/tasks/dp_d)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_d) | -| 0-1 Knapsack | | Subset Sum | you are given a set of integers and a target sum. The task is to determine whether there exists a subset of the given set whose elements sum up to the target sum. | | | Longest Increasing Subsequence | It's a problem that asks for the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. | [Longest Increasing Subsequence - LeetCode](https://leetcode.com/problems/longest-increasing-subsequence/description/) | | Counting all possible paths in a matrix. | Solved using dynamic programming or recursion with memoization. | [Unique Paths - LeetCode](https://leetcode.com/problems/unique-paths/description/) | From 357286307241bcba160af5b2c9ac8a85135a6ca1 Mon Sep 17 00:00:00 2001 From: "Zyad M. Ayad" <36793243+Zyad-Ayad@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:50:59 +0200 Subject: [PATCH 5/6] Update intro-to-dp.md - Problems descriptions/examples are short and uniform. - Added separate list for topic (BitmaskDP, DigitDP and DP on Trees) --- src/dynamic_programming/intro-to-dp.md | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/dynamic_programming/intro-to-dp.md b/src/dynamic_programming/intro-to-dp.md index eb3302a93..06649670e 100644 --- a/src/dynamic_programming/intro-to-dp.md +++ b/src/dynamic_programming/intro-to-dp.md @@ -130,21 +130,22 @@ That's it. That's the basics of dynamic programming: Don't repeat work you've do One of the tricks to getting better at dynamic programming is to study some of the classic examples. ## Classic Dynamic Programming Problems -| Name | Description | Example Poblems | -| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- | -| 0-1 Knapsack | 0-1 Knapsack | given a set of items, each with a weight and a value, and a knapsack with a maximum capacity. | [D - Knapsack 1 (](https://atcoder.jp/contests/dp/tasks/dp_d)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_d) | -| Subset Sum | you are given a set of integers and a target sum. The task is to determine whether there exists a subset of the given set whose elements sum up to the target sum. | | -| Longest Increasing Subsequence | It's a problem that asks for the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order. | [Longest Increasing Subsequence - LeetCode](https://leetcode.com/problems/longest-increasing-subsequence/description/) | -| Counting all possible paths in a matrix. | Solved using dynamic programming or recursion with memoization. | [Unique Paths - LeetCode](https://leetcode.com/problems/unique-paths/description/) | -| Longest Common Subsequence | Given two sequences (usually strings), the task is to find the length of the longest subsequence that is common to both sequences. | [F - LCS (](https://atcoder.jp/contests/dp/tasks/dp_f)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_f) | -| Longest Path in a Directed Acyclic Graph (DAG) | Unlike finding the longest path in a general graph, which is an NP-hard problem, finding the longest path in a DAG can be solved efficiently using dynamic programming. | [G - Longest Path (](https://atcoder.jp/contests/dp/tasks/dp_g)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_g) | -| Longest Palindromic Subsequence | Finding the Longest Palindromic Subsequence (LPS) of a given string. | [Longest Palindromic Subsequence - LeetCode](https://leetcode.com/problems/longest-palindromic-subsequence/description/) | -| Rod Cutting | It involves finding the maximum revenue that can be obtained by cutting a rod of length n into smaller pieces and selling them. | | -| Edit Distance | It involves finding the minimum number of operations required to transform one string into another, where the allowed operations are insertion, deletion, or substitution of a single character. | [CSES - Edit Distance](https://cses.fi/problemset/task/1639) | -| Bitmask Dynamic Programming | Bitmask Dynamic Programming is a technique used to solve combinatorial optimization problems, where the state can be represented compactly using bitmasks. | [Problem - F - Codeforces](https://codeforces.com/contest/1043/problem/F) | -| Digit Dynamic Programming | Digit Dynamic Programming is a technique used to solve problems related to digits of a number. | [SPOJ.com](http://SPOJ.com) [- Problem PR003004](https://www.spoj.com/problems/PR003004/) | -| Dynamic Programming on Trees | A technique used to solve various problems related to trees, such as finding the longest path, computing subtree properties, or counting certain structures within the tree. | [P - Independent Set (](https://atcoder.jp/contests/dp/tasks/dp_p)[atcoder.jp](http://atcoder.jp)[)](https://atcoder.jp/contests/dp/tasks/dp_p) | -| Range Dynamic Programming | Range Dynamic Programming is a technique used to solve problems where you need to find optimal solutions for subranges within a given range or array. | | +| Name | Description/Example | +| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 0-1 knapsack | Given $W$, $N$, and $N$ items with weights $w_i$ and values $v_i$, what is the maximum $\sum_{i=1}^{k} v_i$ for each subset of items of size $k$ ($1 \le k \le N$) while ensuring $\sum_{i=1}^{k} w_i \le W$? | +| Subset Sum | Given $N$ integers and $T$, determine whether there exists a subset of the given set whose elements sum up to the $T$. | +| Longest Increasing Subsequence | You are given an array containing $N$ integers. Your task is to determine the LCS in the array, i.e., LCS where every element is larger than the previous one. | +| Counting all possible paths in a matrix. | Given $N$ and $M$, count all possible distinct paths from $(1,1)$ to $(N, M)$, where each step is either from $(i,j)$ to $(i+1,j)$ or $(i,j+1)$. | +| Longest Common Subsequence | You are given strings $s$ and $t$. Find the length of the longest string that is a subsequence of both $s$ and $t$. | +| Longest Path in a Directed Acyclic Graph (DAG) | Finding the longest path in Directed Acyclic Graph (DAG). | +| Longest Palindromic Subsequence | Finding the Longest Palindromic Subsequence (LPS) of a given string. | +| Rod Cutting | Given a rod of length $n$ units, Given an integer array cuts where cuts[i] denotes a position you should perform a cut at. The cost of one cut is the length of the rod to be cut. What is the minimum total cost of the cuts. | +| Edit Distance | The edit distance between two strings is the minimum number of operations required to transform one string into the other. Operations are ["Add", "Remove", "Replace"] | + +## Related Topics +* Bitmask Dynamic Programming +* Digit Dynamic Programming +* Dynamic Programming on Trees Of course, the most important trick is to practice. From ff4b38046067c1e90975db144af8cd303c69ce21 Mon Sep 17 00:00:00 2001 From: Oleksandr Kulkov Date: Sun, 9 Jun 2024 02:06:32 +0200 Subject: [PATCH 6/6] Touch for CI