跳至主要內容
產品桌面工具TASTECAD圖面檢視TASTEFILES檔案管理TASTEFTP檔案傳輸TASTESSH遠端工作空間TASTEZIP壓縮與解壓縮TASTEWINM檔案管理開發工具TASTECODERust 整合開發環境TASTESTUDIO整合開發與測試環境TASTEETL資料整合(ETL)伺服器TASTEREMOTE遠端桌面伺服器TASTEGEO空間資訊伺服器TASTEMAIL郵件工作空間投資TASTESTOCK股票自動交易桌面應用程式開始使用下載文件購買所有產品
市集
資訊
技術資訊今日開發資訊開發文件程式語言RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular伺服器框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express應用程式與桌面框架TauriFlutterReact NativeElectron演算法演算法基礎核心演算法進階演算法實務演算法
社群專案開發日誌提示詞AI 工具問題作品展示社群指南
合作技術傳授網站建置桌面應用程式建置發布與付款流程銷售合作夥伴聯絡我們
服務遠端桌面安裝包客製
TASTEDEV
產品

桌面工具

TASTECAD再複雜的圖面,也能輕鬆開啟TASTEFILES只挑需要的檔案,最快送達TASTEFTP讓檔案往來,走最俐落的路TASTESSH在你與伺服器之間,築起更穩固的連線TASTEZIP壓得更快,解得更安心TASTEWINM以鍵盤為主、用兩個窗格整理檔案的檔案管理器

開發工具

TASTECODE在一個視窗中完成 Rust 應用程式的編輯、建置、偵錯與測試TASTESTUDIO從編輯到遠端測試,再到經核准的 AI 修正TASTEETL邊看數值,邊搬資料

伺服器

TASTEREMOTE在自己的伺服器上運行的遠端桌面TASTEGEO以 Rust 重新打造相容 GeoServer 的空間資訊伺服器TASTEMAIL把郵件的主導權拿回自己手上

投資

TASTESTOCK何時、做什麼——依你訂下的規則運作的股票自動交易

開始使用

下載所有產品的最新版本文件各產品使用方法購買訂閱與永久授權所有產品一覽全部產品
所有產品
市集資訊
技術

資訊

今日開發資訊語言、框架、GitHub 與 AI 官方發布開發文件語言、框架與演算法指南

程式語言

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

框架

Web 前端框架Next.jsReactVue.js · NuxtSvelteKitAngular
伺服器框架Spring BootDjangoFastAPIASP.NET CoreNestJS · Express
應用程式與桌面框架TauriFlutterReact NativeElectron

演算法

演算法基礎複雜度分析 · 排序 · 搜尋 · 基礎資料結構 · 樹與堆積核心演算法圖形走訪 · 最短路徑與最小生成樹 · 動態規劃 · 貪婪演算法 · 分治法 · 回溯法進階演算法字串演算法 · 數學與數論 · 位元運算 · 線段樹 · 併查集實務演算法程式面試解題策略 · LRU 快取 · 速率限制 · 一致性雜湊
查看全部開發文件
社群
專案探索開發者與作品開發日誌決策與試錯提示詞可重複使用的指令AI 工具問題Claude、Codex、Gemini 的問題與替代做法作品展示已完成的成果社群指南我們如何公開打造
合作
技術傳授用 Rust 與 egui 打造原生應用程式網站建置10 種語言、帳號、文件與下載桌面應用程式建置Rust 與 egui,不用 WebView發布與付款流程簽章、MSI、deb、rpm、AppImage、雜湊銷售合作夥伴推薦即得 30%聯絡我們開發、合作與投資諮詢
服務
遠端桌面用瀏覽器連線你的電腦安裝包客製只裝需要的,設定預先放好
購買
繁
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
登入
登入
TASTEDEV

從小工具到更好的開發。

support@tastedev.net支持 TASTEDEV
產品產品系列購買文件下載市集客戶支援
社群專案開發日誌提示詞AI 工具問題作品展示
政策關於我們隱私權政策服務條款訂閱條款退款政策社群規範
帳戶登入註冊
訪客
今天
昨天
累計瀏覽
公司名稱
GXSOFT
負責人
CHOI YOUNG GU
營業登記號碼
853-44-00368
地址
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
電子郵件
whitecalvin@tastedev.net
個人資料保護負責人
CHOI YOUNG GU

© 2026 TASTEDEV產品資訊以經驗證的開發原始碼為準。已發布·持續改進

動態規劃 文件
動態規劃
ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
討論

動態規劃 指南 · 6/6

Real-World Use

本章目前僅提供英文版。

Many everyday tools run a DP inside, often under a different name. This chapter surveys them, shows two small examples and lists the mistakes that most often break DP code.

Where DP shows up

  • Diff and version control: comparing two files is an LCS / shortest edit script problem. GNU diff and Git's default diff use Myers' algorithm, which runs in O(ND) time for D differences.
  • Spell checking and fuzzy search: edit distance (Levenshtein) ranks candidate words by how many keystrokes separate them from the query.
  • Bioinformatics: Needleman-Wunsch (global) and Smith-Waterman (local) align DNA or protein sequences with a scored edit-distance table.
  • Speech, text and signals: the Viterbi algorithm finds the most likely hidden-state sequence in a hidden Markov model, for speech recognition, part-of-speech tagging and decoding convolutional codes.
  • Networking: distance-vector routing protocols such as RIP are built on the Bellman-Ford recurrence.
  • Databases: query planners choose join orders with DP over subsets of tables, an idea from IBM's System R. PostgreSQL switches from this search to its genetic optimizer (GEQO) when a query joins many tables.
  • Typesetting: TeX's Knuth-Plass line breaking picks break points for a whole paragraph by minimizing total "badness".
  • Planning: value iteration in reinforcement learning applies the Bellman equation; budgeting and cargo loading are knapsack variants.

Example: suggest the closest command

A CLI can suggest a fix for a mistyped command using edit distance with a rolling row.

def edit_distance(s: str, t: str) -> int:
    prev = list(range(len(t) + 1))
    for i, a in enumerate(s, start=1):
        cur = [i] + [0] * len(t)
        for j, b in enumerate(t, start=1):
            cur[j] = prev[j - 1] if a == b else 1 + min(prev[j], cur[j - 1], prev[j - 1])
        prev = cur
    return prev[-1]


def suggest(word: str, commands: list[str], max_distance: int = 2) -> str | None:
    best = min(commands, key=lambda c: edit_distance(word, c))
    return best if edit_distance(word, best) <= max_distance else None


print(suggest("stauts", ["status", "commit", "push", "stash"]))  # status
print(suggest("deploy", ["status", "commit", "push", "stash"]))  # None

Python's difflib.get_close_matches is similar, but it ranks by a SequenceMatcher similarity ratio, not minimal edit distance.

Example: Viterbi on a tiny model

A monitor sees responses as "fast" or "slow" and guesses whether the server was "ok" or "degraded" at each moment. Viterbi keeps, for each state at time t, the best path probability and a back pointer.

對本章有疑問嗎?
上一章Practice Problems
def viterbi(observations, states, start, trans, emit):
    best = [{s: (start[s] * emit[s][observations[0]], None) for s in states}]
    for obs in observations[1:]:
        prev = best[-1]
        best.append({
            s: max((prev[p][0] * trans[p][s] * emit[s][obs], p) for p in states)
            for s in states
        })
    state = max(states, key=lambda s: best[-1][s][0])
    path = [state]
    for layer in reversed(best[1:]):
        state = layer[state][1]
        path.append(state)
    return path[::-1]


states = ("ok", "degraded")
start = {"ok": 0.9, "degraded": 0.1}
trans = {"ok": {"ok": 0.95, "degraded": 0.05}, "degraded": {"ok": 0.2, "degraded": 0.8}}
emit = {"ok": {"fast": 0.9, "slow": 0.1}, "degraded": {"fast": 0.3, "slow": 0.7}}
print(viterbi(["fast", "fast", "slow", "slow", "slow", "fast"], states, start, trans, emit))
# ['ok', 'ok', 'degraded', 'degraded', 'degraded', 'degraded']

Real implementations add log probabilities, because long products of small numbers underflow to zero.

Common pitfalls

  • Wrong state: if the answer depends on something the state does not record (remaining capacity, previous choice), the cache returns answers for the wrong situation.
  • Loop direction: in the one-row 0/1 knapsack, iterating capacities upwards silently turns it into the unbounded knapsack.
  • Recursion depth: Python's default limit is about 1000 frames; long chains need a bottom-up loop.
  • Overflow: counts grow fast. Use 64-bit integers or a modulus in C++ and Java.
  • Unbounded caches: functools.cache never evicts, so a long-running service can grow without limit; use lru_cache(maxsize=...) or clear it.
  • Unhashable arguments: cached functions need hashable arguments, so pass tuples or strings instead of lists.
from functools import cache, lru_cache


@cache
def total(items: tuple[int, ...]) -> int:
    return sum(items)


try:
    total([1, 2, 3])
except TypeError as error:
    print("lists cannot be cache keys:", error)
print(total((1, 2, 3)))  # 6


@lru_cache(maxsize=1024)  # evicts least recently used entries
def score(word: str) -> int:
    return sum(map(ord, word))


score.cache_clear()  # or free everything explicitly

Summary

  • DP powers diff, spell checking, sequence alignment, speech decoding, routing, query planning and typesetting.
  • Production code adds log probabilities, bounded caches or rolling rows to the textbook recurrence.
  • Most DP bugs come from an incomplete state, a wrong loop direction, recursion limits or overflow.

Further reading

  • Dynamic programming (Wikipedia)
  • functools: cache and lru_cache (Python docs)
  • Introduction to Dynamic Programming (cp-algorithms)
  • MIT 6.006 Introduction to Algorithms (MIT OpenCourseWare)
  • Needleman-Wunsch algorithm (Wikipedia)
  • Viterbi algorithm (Wikipedia)
  • Genetic Query Optimizer (PostgreSQL docs)

0 則留言

熱門留言由新到舊

登入 · 登入後即可留言。