本题的题意理解之后,就是求最长回文子序列 longest palindrome subsequence,这里注意子序列和子串的区别。
有两种求法,一种是直接求,相当于填矩阵右上对角阵,另一种是转化为longest common subsequence的求法。
最大难点就是要求内存不能使用二维的。 故此第一种方法是有点难度的,因为需要把二维矩阵的对角线转化为一维表记录,对好下标就好了。
第二中...
分类:
其他好文 时间:
2014-08-02 23:32:34
阅读次数:
326
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
/**
* Definition for binary tree
...
分类:
其他好文 时间:
2014-08-02 23:32:04
阅读次数:
232
~~~~
两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度。
貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛。。
~~~~
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1087
http://poj.org/problem?id=2533
~~~~
HDU1087:
#include...
分类:
其他好文 时间:
2014-08-02 23:30:15
阅读次数:
243
实例一、substring(int beginIndex,int endIndex)String end ="2007-12-31";System.out.println(end.substring(8,10));输出结果:31下标从0开始数;参数说明:beginIndex - 起始索引(包括)。e...
分类:
编程语言 时间:
2014-08-02 15:25:13
阅读次数:
220
Longest Valid ParenthesesGiven a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substr...
分类:
其他好文 时间:
2014-08-02 04:22:40
阅读次数:
248
UVA 11468 - Substring
题目链接
题意:给定一些模式串,然后给出一些字母出现的概率,每次随机出现一个字母,要求出这些字母出现L个组成的字符串不包含(即不是它的连续字串)已有模式串的概率
思路:AC自动机,先构造出AC自动机,构造的时候利用next数组的特性,记录下每个位置是否有经过一个单词结点,如果有这个结点就是不能走的结点,那么问题就变成了只能在能走的结点上...
分类:
其他好文 时间:
2014-08-01 23:08:22
阅读次数:
275
有一个比较容易出错的点:反转求最长公共子序列,这是错误的想法 1 class Solution { 2 public: 3 string longestPalindrome(string s) { 4 int n = s.length(); 5 int lon...
分类:
其他好文 时间:
2014-08-01 15:28:31
阅读次数:
214
题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For exam....
分类:
编程语言 时间:
2014-08-01 10:30:01
阅读次数:
218
Longest Palindromic SubstringGiven a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there...
分类:
其他好文 时间:
2014-08-01 04:47:25
阅读次数:
243
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, the ...
分类:
其他好文 时间:
2014-07-31 23:46:00
阅读次数:
256