This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/5_Gold/1_Gold_DP.md
2020-06-09 12:36:07 -04:00

5 KiB

slug title author order prerequisites
/gold/dp Introduction to Dynamic Programming Michael Cao 1
Recursion
Silver - Prefix Sums

An introduction to dynamic programming concepts needed for USACO Gold.

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.

Tutorial

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
  • CPC.6
    • examples with nonclassical problems
  • HackerRank DP
    • also covers many classical problems

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. Solutions for most problems (excluding USACO) can be found on Chapter 7 of CPH.

General

Coin Change / Knapsack

(description)

Longest Increasing Subsequence

Additional USACO Problems

  • Fairly Straightforward
  • Trickier
    • Mortal Cowmbat
      • Use Floyd-Warshall, Prefix Sums
      • dp[first i letters form valid combo][last letter] -> time
    • Snakes
      • dp[first m groups][k changes] -> total sum of net sizes
    • Taming the Herd
      • dp[consider first i entries only][last breakout in first i occurs at j][k breakouts among first i entries] -> # changes
    • Stamp Painting
      • must be K consecutive with same color
      • O(NK)\to O(N)
    • Circular Barn Revisited
      • can brute force make your DP easier? (yes)