This commit is contained in:
Nathan Wang 2020-06-04 15:32:31 -07:00
commit a3183944d0

View file

@ -3,39 +3,44 @@ slug: /gold/dp
title: "Dynamic Programming"
author: Michael Cao
order: 1
prerequisites:
- Prefix Sums
- Recursion
- Bit Operations (for Bitmask DP)
- DFS and Trees (for Tree DP)
---
<div class="syllabus-only">
Description: Todo
Description: An introduction into Dynamic Programming concepts needed (and not-so-needed but still useful) for USACO gold.
</div>
<!-- END DESCRIPTION -->
## Prerequisites
Assumes familiarity with prefix sums, recursion, bit operations (for Bitmask DP), and trees (for Tree DP).
## Introduction to DP
- CPH 7
Dynamic Programming is a very important concept which emerges in the USACO gold division and extends to the IOI. Typically, one or two problems from every contest in the gold division uses some sort of Dynamic programming. The following tutorials serve as an introduction into the mindset of Dynamic programming.
- CPH 7 (Great introduction that covers most classical problems)
- [Topcoder DP (Great for all skill levels)](https://www.topcoder.com/community/competitive-programming/tutorials/dynamic-programming-from-novice-to-advanced/)
- [CPC.6 (Examples with nonclassical problems)](https://github.com/SuprDewd/T-414-AFLV/tree/master/06_dynamic_programming)
- [HackerRank DP](https://www.hackerrank.com/topics/dynamic-programming)
- [Topcoder DP](https://www.topcoder.com/community/competitive-programming/tutorials/dynamic-programming-from-novice-to-advanced/)
- [CPC.6](https://github.com/SuprDewd/T-414-AFLV/tree/master/06_dynamic_programming)
## Classical DP Problems
Tutorials for most problems (excluding USACO) can be found on Chapter 7 of CPH.
Practice makes perfect. Start by doing some classical problems (try at least one of each), as these are **must know** DP problems. Each topic starts with direct applications of the classical problems, and then some interesting variations and USACO problems which utilize the ideas. Tutorials for most problems (excluding USACO) can be found on Chapter 7 of CPH.
* Knapsack
* [Unbounded](https://www.hackerrank.com/challenges/unbounded-knapsack/problem)
* [0/1](https://www.hackerrank.com/contests/srin-aadc03/challenges/classic-01-knapsack/problem)
* [Large Capacity + Small Values](https://atcoder.jp/contests/dp/tasks/dp_e)
* Reconsider the state.
* [Talent Show (USACO Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=839)
* [Fruit Feast (USACO Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=574)
* Longest Increasing Subsequence
* [LIS in Quadratic Time](https://leetcode.com/problems/longest-increasing-subsequence/)
* Try to improve to $O(N\log N)$.
* [Sort It Out (USACO Platinum)](http://www.usaco.org/index.php?page=viewproblem2&cpid=865)
* Challenging!
* Coin Change
* [Unordered](https://cses.fi/problemset/task/1635)
* [Ordered](https://cses.fi/problemset/task/1636)
@ -43,21 +48,28 @@ Tutorials for most problems (excluding USACO) can be found on Chapter 7 of CPH.
* Paths on a Grid
* [Count Paths](https://atcoder.jp/contests/dp/tasks/dp_h)
* [Palindromic Paths (Old USACO Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=553)
* Consider the answer. What are some properties of it?
* Edit Distance
* [Standard](https://www.hackerrank.com/contests/cse-830-homework-3/challenges/edit-distance)
* [Landscaping (Silver)](http://www.usaco.org/index.php?page=viewproblem2&cpid=126)
* Although the problem looks different, this is actually a direct application of Edit Distance.
* Longest Common Subsequence
* [Standard](https://leetcode.com/problems/longest-common-subsequence/)
## Tree DP
Assumes familiarity with the structures of trees, and basic algorithms to traverse them (eg. dfs) to perform the DP.
* Tutorial
* [DP on Trees (Codeforces)](https://codeforces.com/blog/entry/20935)
* Add more?
* Problems
* [Subtree](https://atcoder.jp/contests/dp/tasks/dp_v)
* [Independent Set](https://atcoder.jp/contests/dp/tasks/dp_p)
* [Barn Painting (USACO Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=766)
* Similar to Independent Set
* [Delegation (USACO Gold)](http://usaco.org/index.php?page=viewproblem2&cpid=1019)
* Good rule of solving DP problems applies here: don't just dive into trying to figure out a DP state and transitions, and make some observations about the problem first.
## Bitmask DP
@ -96,5 +108,7 @@ Note: Has not appeared on recent USACO.
* [Hoof Paper Scissors](http://www.usaco.org/index.php?page=viewproblem2&cpid=694)
* [Cow Checklist](http://www.usaco.org/index.php?page=viewproblem2&cpid=670)
* [Circular Barn Revisited](http://www.usaco.org/index.php?page=viewproblem2&cpid=622)
* can brute force make your DP easier? (yes)
* [Radio Contact](http://www.usaco.org/index.php?page=viewproblem2&cpid=598)
* [248](http://www.usaco.org/index.php?page=viewproblem2&cpid=647)
* on ranges