Word Break II
Given a string and a dictionary of words, find all ways to break the string into valid words.
Return all possible sentences where each word is in the dictionary.
这道题本质上是“单词拆分 II”:给定字符串和词典,要枚举所有能够把字符串完整切分成合法单词的方案,而不是只判断能否切分。常见做法是先用动态规划或记忆化搜索判断从某个位置开始是否可达,避免重复子问题;再配合 DFS/ 回溯按前缀逐步扩展,拼出所有合法句子。题目的关键在于同时处理“可行性剪枝”和“结果枚举”,这样既能保证正确性,也能避免指数级重复搜索。
正文完