๐Ÿ› ๏ธ Steven Gong

Search

SearchSearch
Aug 03, 2024 ยท 1 min read ยท 46 views ยท 2 in the last 30 days
Reader snapshot

Where readers are reading from

FijiTanzaniaWestern SaharaCanada ยท 0 readersUnited States of America ยท 0 readersKazakhstanUzbekistanPapua New GuineaIndonesia ยท 0 readersArgentinaChileDemocratic Republic of the CongoSomaliaKenyaSudanChadHaitiDominican RepublicRussiaThe BahamasFalkland IslandsNorwayGreenlandFrench Southern and Antarctic LandsEast TimorSouth AfricaLesothoMexicoUruguayBrazil ยท 0 readersBoliviaPeruColombiaPanamaCosta RicaNicaraguaHondurasEl SalvadorGuatemalaBelizeVenezuelaGuyanaSurinameFranceEcuadorPuerto RicoJamaicaCubaZimbabweBotswanaNamibiaSenegalMaliMauritaniaBeninNigerNigeriaCameroonTogoGhanaIvory CoastGuineaGuinea-BissauLiberiaSierra LeoneBurkina FasoCentral African RepublicRepublic of the CongoGabonEquatorial GuineaZambiaMalawiMozambiqueEswatiniAngolaBurundiIsraelLebanonMadagascarPalestineThe GambiaTunisiaAlgeriaJordanUnited Arab EmiratesQatarKuwaitIraqOmanVanuatuCambodiaThailand ยท 0 readersLaosMyanmarVietnam ยท 0 readersNorth KoreaSouth KoreaMongoliaIndia ยท 1 readersBangladesh ยท 0 readersBhutanNepalPakistanAfghanistanTajikistanKyrgyzstan ยท 0 readersTurkmenistanIranSyriaArmeniaSwedenBelarusUkraine ยท 0 readersPoland ยท 0 readersAustriaHungaryMoldova ยท 0 readersRomania ยท 0 readersLithuaniaLatviaEstoniaGermanyBulgariaGreeceTurkeyAlbaniaCroatiaSwitzerlandLuxembourgBelgiumNetherlandsPortugalSpainIrelandNew CaledoniaSolomon IslandsNew ZealandAustraliaSri LankaPeople's Republic of China ยท 0 readersTaiwanItalyDenmarkUnited Kingdom ยท 0 readersIcelandAzerbaijanGeorgiaPhilippinesMalaysiaBruneiSloveniaFinlandSlovakiaCzech RepublicEritreaJapan ยท 0 readersParaguayYemenSaudi ArabiaTurkish Republic of Northern CyprusCyprusMoroccoEgyptLibyaEthiopiaDjiboutiSomalilandUgandaRwandaBosnia and HerzegovinaNorth MacedoniaSerbiaMontenegroKosovoTrinidad and TobagoSouth SudanSelect a country to explore ยท Last 30 days
Singapore1
India1
China0
Canada0
United States0
Vietnam0
Traffic ยท last 30 days000Sep 16Sep 26Oct 6Oct 15
views
Traffic ยท all time012Aug 3Aug 6Aug 9Aug 12Aug 14
views

Dynamic Programming

DP on Trees

Sometimes, there are tree problems, and you need do DP on them.

Resources

  • https://usaco.guide/gold/dp-trees?lang=cpp
  • https://codeforces.com/blog/entry/20935

It seems intimidating at first, but when you really look at it, itโ€™s not that hard, not much different than regular DP.

Instead of something like

dp[i] = max(A[i] + dp[i+2], dp[i+1])

You need do it on trees

dp[i] = max(A[i] + sum_grandchild[i+1], SUM child[i])

Seems like they like to use dp1 and dp2.

Graph View

Backlinks

  • No backlinks found

Created with Quartz, ยฉ 2026

  • Blog
  • LinkedIn
  • Twitter
  • GitHub