GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LeetCode/Dynamic_Programming/131.Palindrome-Partitioning at master · wisdompeak/LeetCode

Expand file tree

/

131.Palindrome-Partitioning

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

131.Palindrome-Partitioning

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
131.Palindrome-Partitioning.cpp
131.Palindrome-Partitioning.cpp
 
 
131.Palindrome-Partitioning.py
131.Palindrome-Partitioning.py
 
 
Readme.md
Readme.md
 
 

Readme.md

131.Palindrome-Partitioning

首先预处理字符串,用区间型dp计算出任意两个index之间的substring是否是回文串,记做dp[i][j].

然后从第一个字符开始进行深度优先搜索。设计dfs(i,temp),表示考虑以当前的位置i为substring的开头,遍历有哪些位置j满足[i:j]的字符串满足回文(即dp[i][j]=1),就将该字符串收录进temp,然后递归搜索第j+1个位置。如果dfs的参数i走到了n,说明恰好将整个s分割成了若干段回文串,就将这组分割的子串temp加入最终答案。

特别注意,这个dfs在回溯的时候需要将temp末尾加入的子串弹出。

Leetcode Link

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.