码迷,mamicode.com
首页 >  
搜索关键字:maximum sum subarray    ( 25087个结果
LeetCode OJ - Max Points on a Line
题目: Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.解题思路: 第一反应:枚举两个点组成的直线,然后看其他的点在不在这条直线上,在此过程中统计最大.....
分类:其他好文   时间:2014-05-16 05:54:57    阅读次数:193
HDU 4059 The Boss on Mars-矩阵+容斥
错了29遍,终成正果。。。。。 根据题意,很容易的可以想到容斥。 然后的问题就是如何求 sum(n)=1^4+2^4+3^4+....+n^4; 有三种道路: 很显然:1^4+2^4+3^4+....+n^4=(n^5)/5+(n^4)/2+(n^3)/3-n/30; 则1,用java的大数去敲这个的代码。 2,用c++敲,但是用到分数取模,求逆元。 3,用c++敲,但是不用这...
分类:其他好文   时间:2014-05-15 06:36:06    阅读次数:328
[LeetCode] K sum(2Sum、3Sum、4Sum)
2Sum & 3Sum & 4Sum & KSum...
分类:其他好文   时间:2014-05-15 05:33:56    阅读次数:270
leetcode第一刷_Combination Sum Combination Sum II
啊啊啊啊,好怀念这种用递归保存路径然后打印出来的题目啊,好久没遇到了。 分了两种,一种是可以重复使用数组中数字的,一种是每个数字只能用一次的。其实没有多大区别,第一种每次进入递归的时候都要从头开始尝试,第二种要找一个标记的数组,把已经用到过的排除掉,就像生成全排列时的做法一样。跟我一样用引用保存中间结果的话,要注意回退的情况。第二种回退时,要把用到的那个数也恢复为可用,就完全像全排列时做的一样。...
分类:其他好文   时间:2014-05-15 04:46:34    阅读次数:272
LeetCode-001 Two Sum
LeetCode-001 Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2...
分类:其他好文   时间:2014-05-15 04:34:50    阅读次数:293
LeetCode-005 Longest Palindromic Substrin
【题目】 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. 【题意】 题意是找出字符串S中最长回文子串,S最长为1000,保证有唯一解 【思路】 原字符串用特殊字符#间隔,如下所示: #a...
分类:其他好文   时间:2014-05-15 03:31:25    阅读次数:299
UVALive 6609(Minimal Subarray Length)维护递增序列|RMQ
题意:给一个整数序列(可能有负数),求最短的连续序列使得序列之和大于等于整数x; 解法:第一种是On的复杂度:                   我们要的是sum[j]-sum[i]>=x,如果有两个决策j = sum[j'],那么j就是没用的。即维护一个sum[j]递增序列。然后每次可以二分查找,但是这里有个特点就是要得到最近的,可以同时维护一个left指针,left指针用于跟进更...
分类:其他好文   时间:2014-05-15 03:20:26    阅读次数:303
HDU 4635
http://acm.hdu.edu.cn/showproblem.php?pid=4635问:最多加多少条边,使得原图不是强连通图正向考虑有困难,不妨反向思考,既最少去掉几条边使得原图不是强连通。总边数sum=n*(n-1)时肯定是强连通,已经给了m条边,sum-=m这时把已经强连通的部分进行缩点...
分类:其他好文   时间:2014-05-14 13:37:36    阅读次数:335
BZOJ3157: 国王奇遇记 & 3516: 国王奇遇记加强版
令\[S_i=\sum_{k=1}^n k^i m^k\]我们有\[\begin{eqnarray*}(m-1)S_i & = & mS_i - S_i \\& = & \sum_{k=1}^n k^i m^{k+1} - \sum_{k=1}^n k^i m^k \\& = & \sum_{k=2...
分类:其他好文   时间:2014-05-14 10:45:13    阅读次数:357
sum max(hdu 1003)
观察可以发现,0,1,2,……,n结尾的分组中,maxsum a[0] = a[0]maxsum a[1] = max( a[0] + a[1] ,a[1]) = max( maxsum a[0] + a[1] ,a[1])maxsum a[2] = max( max ( a[0] + a[1] +...
分类:其他好文   时间:2014-05-14 08:38:58    阅读次数:323
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!