QTREE - Query on a tree
no tags
You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N-1.
We will ask you to perfrom some instructions ...
分类:
其他好文 时间:
2015-08-17 19:35:02
阅读次数:
104
用线段树求解,这里注意由于求的是路径最大值,注意一下细节。
#include
#include
#include
using namespace std;
const int MAXN = 10010;
#define lson (pos<<1)
#define rson (pos<<1|1)
const int INF = (1 << 30);
int n;
//---------------...
分类:
其他好文 时间:
2015-08-16 23:13:03
阅读次数:
141
spoj 1811 LCS - Longest Common Substring
题意:
给出两个串S, T, 求最长公共子串。
限制:
|S|, |T|
思路:
dp O(n^2) 铁定超时
后缀数组 O(nlog(n)) 在spoj上没试过,感觉也会被卡掉
后缀自动机 O(n)
我们考虑用SAM读入字符串B;
令当前状态为s,同时最大匹配长度为len;...
分类:
其他好文 时间:
2015-08-14 21:29:35
阅读次数:
121
spoj 1812 LCS2 - Longest Common Substring II
题意:
给出最多n个字符串A[1], ..., A[n], 求这n个字符串的最长公共子串。
限制:
1
|A[i]|
思路:
和spoj 1811 LCS差不多的做法
把其中一个A建后缀自动机
考虑一个状态s, 如果A之外的其他串对它的匹配长度分别是a[1], a[2],...
分类:
其他好文 时间:
2015-08-14 21:28:39
阅读次数:
233
NSUBSTR - Substringsno tagsYou are given a string S which consists of 250000 lowercase latin letters at most. We define F(x) as the maximal number of ...
分类:
其他好文 时间:
2015-08-14 21:05:34
阅读次数:
228
题目链接:点击进入
树链剖分并不是一个复杂的算法或者数据结构,只是能把一棵树拆成链来处理而已,换一种说法,树链剖分只是xxx数据结构/算法在树上的推广,或者说,树链剖分只是把树hash到了几段连续的区间上。比如说下面这道题,就是将树分为重链和轻链然后映射到线段树上,然后再在线段树上进行查询和修改等操作。所以树链剖分的重点有两个,一是正确的将树分解成几段并映射到线段树上去,二是在线段树中进行查询和修...
分类:
其他好文 时间:
2015-08-13 10:06:22
阅读次数:
119
后缀自动机理解关键点:
1. 根到任意一个结点都可以形成S的一个子串,并且S的所有子串都可以通过这种方式形成;
2. 到达该节点是所有路径就是一个right集合,一个拥有相同后缀的right集合;
3. 设某子串为str,这后缀自动机读入str后能到达的状态为right(str),即str在S中出现的位置的集合;
4. 假设node[b].fa = a,则状态a可以代替状态b进行识别。
...
分类:
其他好文 时间:
2015-08-12 16:58:23
阅读次数:
122
一个数字是Balanced Numbers,当且仅当组成这个数字的数,奇数出现偶数次,偶数出现奇数次一下子就相到了三进制状压,数组开小了,一直wa,都不报re,使用记忆化搜索,dp[i][s] 表示长度为i,状态为s,时,满足条件的balance number的个数#include #include...
分类:
其他好文 时间:
2015-08-09 10:46:00
阅读次数:
93
Harry Potter has n mixtures in front of him, arranged in a row. Each mixture has one of 100 different colors (colors have numbers from 0 to 99).He wan...
分类:
其他好文 时间:
2015-08-07 23:46:58
阅读次数:
245
K-queryGiven a sequence of n numbers a1, a2, ..., anand a number of k- queries. A k-query is a triple (i, j, k) (1 ≤ i ≤...
分类:
其他好文 时间:
2015-08-06 00:00:54
阅读次数:
327