Implement an algorithm to find the kth to last element of a singly linked list.
分类:
其他好文 时间:
2014-07-08 22:01:38
阅读次数:
209
Implement an algorithm to find the kth to last element of a singly linked list.Classical "Runner" Technique of linkedlist/*Use two pointers, forward o...
分类:
其他好文 时间:
2014-07-08 00:37:17
阅读次数:
315
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.public class Solution { public...
分类:
其他好文 时间:
2014-07-06 13:50:22
阅读次数:
153
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist...
分类:
其他好文 时间:
2014-07-03 11:09:35
阅读次数:
185
首先tarjan缩点,重新建图后,每个点的权值就是该点包含点的个数。
然后从入度为0的点开始记忆化搜索,dp[i]表示以i为根最多包含多少点。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define inf 0x3f3f3f3f
#define e...
分类:
其他好文 时间:
2014-07-02 08:37:48
阅读次数:
211
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [?2,1,?3,4,?1,2,1...
分类:
其他好文 时间:
2014-07-01 00:23:01
阅读次数:
248
【问题】
Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
定义一个过程,它以三个数为参数,返回其中较大的两个数的平方和。
【普通版】
(define (sum-square-largest x y ...
分类:
其他好文 时间:
2014-06-30 00:19:52
阅读次数:
270
Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog...
分类:
其他好文 时间:
2014-06-27 23:01:16
阅读次数:
259
题目要求一个最大的弱联通图。
首先对于原图进行强连通缩点,得到新图,这个新图呈链状,类似树结构。
对新图进行记忆化dp,求一条权值最长的链,每个点的权值就是当前强连通分量点的个数。
/*
Tarjan算法求有向图的强连通分量set记录了强连通分量
Col记录了强连通分量的个数。
*/
#include
#include
#include
#include
#include
usin...
分类:
其他好文 时间:
2014-06-27 10:12:12
阅读次数:
275
题目链接:http://acdream.info/problem?pid=1108
题意:n个数的数列,m次查询某个区间出现次数第k多的数出现的次数。n,m
解法:这个因为是离线的所以可以先统一处理,然后再输出。可以维护一个left和right指针,pre,pre[i]表示此时区间内出现次数大于等于i的数的种类。为了减少复杂度,关键是left和right的移动方式,即查询区间如何排...
分类:
其他好文 时间:
2014-06-27 09:38:07
阅读次数:
255