【题目描述】
Given a strings, partitionssuch that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s.
给定一个字符串s,将s分割成一些子串,使每个子串都是回文串。
【题目链接】
www.lintcode.com/en/problem/palindrome-partitioning/
【题目解析】
罗列所有可能,典型的DFS. 此题要求所有可能的回文子串,即需要找出所有可能的分割,使得分割后的子串都为回文。凭借高中的排列组合知识可知这可以用『隔板法』来解决,具体就是在字符串的每个间隙为一个隔板,对于长度为 n 的字符串,共有 n-1 个隔板可用,每个隔板位置可以选择放或者不放,总共有 O(2n−1)O(2^{n-1})O(2n−1) 种可能。由于需要满足『回文』条件,故实际上需要穷举的状态数小于 O(2n−1)O(2^{n-1})O(2n−1).
【参考答案】
www.jiuzhang.com/solutions/palindrome-partitioning/
Lintcode136 Palindrome Partitioning solution 题解
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
BUUCTF题解
CTF三年小白,随笔一写
php 代码审计 PHP -
2024beginctfpwn题解wp
新年快乐CTFer!!
2024beginctf pwn 题解wp -
Beginctf 2024 pwn部分题解
beginctf 2024 pwn 部分题解wp
格式化字符串 beginctf pwn 栈溢出 wp