Tensorum
YouTubeகற்கத் தொடங்குங்கள்

Dynamic Programming

1D, grid, knapsack, LCS, LIS, interval, tree, bitmask மற்றும் digit DP — 24 பேட்டர்ன்களில்.

DSAமேம்பட்டது84 மணி நேரம்24 பேட்டர்ன்கள் · 120 பிராப்ளம்கள்
0%
உங்கள் முன்னேற்றம்

பிராப்ளம் மற்றும் கேஸ் ஸ்டடி பெயர்கள், கோட் மற்றும் தொழில்நுட்பச் சொற்கள் ஆங்கிலத்திலேயே வைக்கப்பட்டுள்ளன.

மைய யோசனை

Recursive brute force எழுதி, அதன் parameters ஐ state என அழைத்து, memoise செய்து, பின் table ஆக மாற்றி, முந்தைய row மட்டும் தேவையெனில் dimensions ஐக் குறையுங்கள்.

எப்போது பயன்படுத்துவது

  • தேர்வுகளின் மீது வழிகளை எண்ணுதல், min/max செலவு அல்லது feasibility
  • Brute-force recursion இல் overlapping subproblems
  • Sequences, grids, knapsacks, intervals, trees

டெம்ப்ளேட்

def lcs(a, b):
    prev = [0] * (len(b) + 1)
    for i in range(1, len(a) + 1):
        cur = [0] * (len(b) + 1)
        for j in range(1, len(b) + 1):
            cur[j] = prev[j-1] + 1 if a[i-1] == b[j-1] else max(prev[j], cur[j-1])
        prev = cur
    return prev[-1]

Complexity

States × transitions — எ.கா. LCS க்கு O(n·m), knapsack க்கு O(n·W).

பொதுவான தவறுகள்

  • எதிர்காலம் சார்ந்திருக்கும் அனைத்தையும் பிடிக்காத state
  • 0/1 vs unbounded knapsack இல் தவறான iteration வரிசை
  • 1-indexed tables மற்றும் 0-indexed strings இடையே off-by-one

அடையாளக் குறிப்புகள்

1DGridKnapsackLCSLISState MachineIntervalPartitionTree/GraphBitmaskDigit