题意:给个n*n的矩阵,所有子矩阵中 ,和最大等于多少。
做法:
首先要理解一个O(n)的算法 。
给一个数组 求连续和的最大值。 可以用一个sum来从下标0开始计算和,不断取最大值。当加和小于0的时候 初始化为0;
如 3 -4 5 1 -2 第一个步加和是3,再加上第二个-4 ,sum就变成-1了,所以要初始化sum为0,再加5 ,再加1, 最后得到最大值为6。
然后对于矩阵,我们可以先预处理,sum[ i ] [ j ]为 第 i 列的 前j项和;
然后枚举 两列 i,j ,然后k...
分类:
其他好文 时间:
2015-02-12 16:21:42
阅读次数:
135
题目链接:http://poj.org/problem?id=3061
题意:给定长度为n的数列整数,以及整数S,求出总和不少于S的连续子序列的长度的最小值。如果解不存在,则输出0。
尺取法:通常是指对数组保存一对下标(起点,终点),然后根据实际情况交替推进两个端点直到解决问题的方法,这个操作很像尺蠼虫故得名。
思路:所以可以先初始化起点s,终点g,再一步一步推进,直到sum>S,然后记录此...
分类:
其他好文 时间:
2015-02-12 09:19:26
阅读次数:
95
整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了。解题思路:经过打表可得规律答案要么是0 要么是2的N次 - 1要得到最大的XOR值,其值一定是2的N次 - 1即在 l 和 r 的二进制中,从左到右遍历过去,如果碰到 (2 ^ i) & l 为 1 , (2 ^ i) & r ...
分类:
其他好文 时间:
2015-02-12 00:32:59
阅读次数:
684
Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig...
分类:
其他好文 时间:
2015-02-11 23:09:04
阅读次数:
154
absolute : to specify an absolute time for a time-range (in time-range configuration mode)no absolutebuffer-length : to specify the maximum length of ...
分类:
移动开发 时间:
2015-02-11 21:50:24
阅读次数:
247
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 le...
分类:
其他好文 时间:
2015-02-10 23:02:36
阅读次数:
218
本文转自:http://www.linuxidc.com/Linux/2013-06/86057.htm关于ora-01000:超出最大可打开的游标数 的一点理解ORA-01000: maximum open cursors exceeded"怎么解决ERROR at line 1:ORA-0100...
分类:
其他好文 时间:
2015-02-10 20:08:34
阅读次数:
162
题目来源,待字闺中,原创@陈利人 ,欢迎大家继续关注微信公众账号“待字闺中”原题这个LIS问题,可不是Longest Increasing Subsequence,而是Largest Independent Set,含义例如以下:给定一棵二叉树,找到满足例如以下条件的最大节点集合:集合中的随意两个节...
分类:
其他好文 时间:
2015-02-10 20:07:30
阅读次数:
194
Find the contiguous subarray within an array (containing at least one number) which has the largest product.
For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the larg...
分类:
其他好文 时间:
2015-02-10 15:26:37
阅读次数:
160
Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa...
分类:
其他好文 时间:
2015-02-10 15:06:02
阅读次数:
172