题目:uva10285 - Longest Run on a Snowboard(记忆化搜索)
题目大意:给出N * N的矩阵,要求找到一条路径,路径上的值是递减的,求这样的路径的最长长度。
解题思路:记忆话搜索。因为要求最长的路径那么就需要将所有的这样的路径找出,但是直接dfs会超时的。对于同一个位置,从这个点出发的最长路径长度是固定的。所以在找的时候就要将这个位置的最长路径...
分类:
其他好文 时间:
2014-08-03 23:29:06
阅读次数:
299
本题的题意理解之后,就是求最长回文子序列 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
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
有一个比较容易出错的点:反转求最长公共子序列,这是错误的想法 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
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
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.算法思路:思路:貌似木有什么捷径,逐个比较,遇到不同即断开。代码如下: 1 publi...
分类:
其他好文 时间:
2014-07-31 23:31:50
阅读次数:
231
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root ...
分类:
其他好文 时间:
2014-07-31 23:19:10
阅读次数:
259