给定一个二叉树,求它的最大深度。最大深度是沿从根节点,到叶节点最长的路径。...
分类:
其他好文 时间:
2014-10-04 01:10:05
阅读次数:
186
题目地址:Ural 1146
这题是求最大子矩阵和。方法是将二维转化一维。
首先用n*n的方法来确定矩阵的列。需要先进行预处理,只对每行来说,转化成一维的前缀和,这样对列的确定只需要前后两个指针来确定,只需要用前缀和相减即可得到。前后两个指针用n*n的枚举。
确定好了哪几列,那么再确定行的时候就转化成了一维的最大连续子序列的和。再来一次O(n)的枚举就可以。
这样,总复杂就变成了O(n^3...
分类:
其他好文 时间:
2014-10-03 22:40:35
阅读次数:
205
题目Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete...
分类:
其他好文 时间:
2014-10-03 13:37:34
阅读次数:
225
Problem Description
Jack and Jill play a game called "Leap Frog" in which they alternate turns jumping over each other. Both Jack and Jill can jump a maximum horizontal distance of 10 units in any ...
分类:
其他好文 时间:
2014-10-03 00:03:23
阅读次数:
361
Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a...
分类:
其他好文 时间:
2014-10-02 13:58:53
阅读次数:
321
[leetcode]Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring....
分类:
其他好文 时间:
2014-10-02 13:30:42
阅读次数:
217
最近一直忙着写paper,很久没做题,一下子把题目搞复杂了。。思路理清楚了非常简单,每次只需更新2个值:最大乘积和最小乘积。最大乘积被更新有三种可能:当前A[i]>0,乘以前面最大的数(>0),得到新的最大乘积;当前A[i]0,(A[i-1]==0。最小乘积同理。。
class Solution {
public:
int Max(int a, int b, int c)
{...
分类:
其他好文 时间:
2014-10-02 02:54:12
阅读次数:
170
题目大意:
给出一棵树,每个点有商店,每个商店都有一个价格,Yaoge每次从x走到y都可以在一个倒卖商品,从中得取利益,当然,买一顶要在卖之前。但是没次走过一条路,这条路上的所有商品都会增加一个v。
输出每次的最大利益。
思路分析:
很容易想到树链剖分,可是关键在于如何维护这样一个变量,使得每次都要让买的再卖的前面。
维护变量 ltr 和 rtl ,表示从左去右和从右去左。
剖...
分类:
其他好文 时间:
2014-10-01 18:01:37
阅读次数:
268
Given a string S,
find the longest palindromic substring in S.
You may assume that the maximum length of S is
1000, and there exists one unique longest palindromic substring.
面DP题的考官都是神经病。。(吐...
分类:
其他好文 时间:
2014-10-01 13:15:31
阅读次数:
242
这题看起来和max subarray差不多,只是加法变乘法,尝试过用分治法,发现划分情况的时候特别麻烦。于是分析下这题本身的特点:1、对0较敏感,一旦有0,乘积就不变了,所以需要在遇到0 的时候将数组拆分2、如果没有0, 一旦相乘,绝对值肯定会变大,所以仅考虑正负号的问题就够了。若整个数组相乘是一个...
分类:
其他好文 时间:
2014-09-30 17:23:59
阅读次数:
206