题目意思是给你一个字符串,f[x]是长度为x的子串中,出现个数最多的那个串的出现次数。给出原串,依次输出f[1],f[2],……。后缀自动机。对于某一个状态,right[]值的大小就是出现的次数,而且是对于长为step[]的子串的出现次数。因为小于step值的串在前面已经加了,在pre指针线上面的状...
分类:
其他好文 时间:
2014-06-23 07:14:18
阅读次数:
254
题目:Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary ...
分类:
其他好文 时间:
2014-06-21 07:03:28
阅读次数:
249
题目:Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.个人思路:1、选...
分类:
其他好文 时间:
2014-06-21 06:37:00
阅读次数:
183
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.说明:平衡二叉搜索树,即任何结点的左子树和右子树高度最多相差1的二叉搜索树。二叉搜索树:二叉查找树(Bin...
分类:
其他好文 时间:
2014-06-21 00:47:08
阅读次数:
221
经典题目:给一个字符串,求字典序第k小的子串是什么。涉及子串问题,上自动机。首先我们可以用记忆化搜索的方法,求出到达某一个状态后,能产生多少个新状态。首先,到达这个状态就不走了,这肯定是一种状态,然后分别考虑后面的26个指针就好了。不过如果不记忆化肯定是要T的,而且如果用dp好像会有一点问题,因为状...
分类:
其他好文 时间:
2014-06-20 18:54:41
阅读次数:
163
和上个题目差不多,这次是找若干个串的LCS,若干#include #define maxn 200100using namespace std;int next[maxn][26],pre[maxn],step[maxn];int f[13][maxn];int N=0,last=0,n=1;int...
分类:
其他好文 时间:
2014-06-20 18:49:21
阅读次数:
153
经典题目,求两个串的最长公共子串。是这样来做的。以第一个串构造SAM,第二个串在自动机上跟新一遍就可以了。更新的过程是这样的,假设当前到达的状态点为x(初始状态为0点),下一个字符是c,如果当前状态没有c这条边就一直沿着pre指针走,直到找到第一个有c这条边的状态或者确认全部都没有。更新是这样的,用...
分类:
其他好文 时间:
2014-06-20 18:40:05
阅读次数:
207
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe...
分类:
其他好文 时间:
2014-06-19 11:23:05
阅读次数:
204
Given an array where elements are sorted in
ascending order, convert it to a height balanced BST.递归,二分法。 1 /** 2 *
Definition for binary tree 3 * st.....
分类:
其他好文 时间:
2014-06-16 00:33:31
阅读次数:
252
当初第一次做的是FPLICE这个题,当时就觉得要用图论去搜索,但是当时陷入死思维就是 dp[][]两个维度都是点,这样就违背了题目的本意,题目给定了一个时间T,在不超过时间T的情况下求最小的消耗,这不就是背包嘛。。。即拿T做容量,在图上面 设置 dp[i][j]表示i点的时候 j时间的最小消耗。这样...
分类:
其他好文 时间:
2014-06-14 23:18:41
阅读次数:
298