传送门 f[i][j] 表示区间 i 到 j 变为回文串所需最小费用 1.s[i] == s[j] f[i][j] = f[i + 1][j - 1] 2.s[i] != s[j] f[i][j] = min(f[i + 1][j] + cost[s[i]], f[i][j - 1] + cost[ ...
分类:
其他好文 时间:
2017-05-30 21:53:21
阅读次数:
122
Given an integer n, find the closest integer (not including itself), which is a palindrome. The 'closest' is defined as absolute difference minimized ...
分类:
其他好文 时间:
2017-05-28 12:28:00
阅读次数:
229
【题目】 Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. For e ...
分类:
其他好文 时间:
2017-05-27 17:58:45
阅读次数:
105
题意:一个长为N的字符串( 3 <= N <= 5000)。问最少插入多少个字符使其变成回文串。 题目链接:http://poj.org/problem?id=1159 ——>>状态:dp[i][j]表示第i个字符到第j个字符组成的字符串变成回文串的最少插入次数。 状态转移方程: 若sz[i] == ...
分类:
编程语言 时间:
2017-05-26 10:43:14
阅读次数:
237
题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #inc ...
分类:
其他好文 时间:
2017-05-24 18:22:26
阅读次数:
227
1. 生成回文序列——对于输入的整数或字符串,生成一个它的回文,长度是输入的2倍。 2. 判断回文序列——使用循环 3. 判断回文序列——不使用循环,如果是字符串是回文, 输出1,否则为0 ...
分类:
其他好文 时间:
2017-05-23 21:45:31
阅读次数:
151
题目: Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 题解: 推断一个链表是不是回文的,这里要求O(n)时间复杂 ...
分类:
编程语言 时间:
2017-05-22 17:48:12
阅读次数:
107
564 Find the Closest Palindrome:给出一个长度不超过18的非负整数,求出与其最近接的回文整数(不包括它自己)。 思路:假设其长度为偶数。将其分为两半,前一半设为$x$,那么最后的答案的前一部分一定是$x-1,x,x+1$三个中的一个。在这里,$x-1$有可能变成少一位的 ...
分类:
其他好文 时间:
2017-05-20 22:38:46
阅读次数:
138
方法:使用深度遍历的方法,时间复杂度O(2^n) ...
分类:
其他好文 时间:
2017-05-20 16:31:40
阅读次数:
199
题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Exampl ...
分类:
其他好文 时间:
2017-05-17 22:09:47
阅读次数:
228