题目链接:http://codeforces.com/gym/100548 今天晚上突然有了些兴致去学习一下数据结构,然后就各种无意中看到了Palindrome Tree的数据结构,据说是2014年新出的数据结构,也让我回想起了西安打铁时候的经历.这道题的题意其实是比较清晰的,给你两个长度200000的字符串,求它们有多少对回文子串.处理字符串有许多常用的工具,像后缀数组,后缀自动机,AC自动机,KMP,但是这些数据结构在针对回文串的处理上都不是特别强,当然稍微处理一下我们还是可以很好的利用好上…
The Problem to Slow Down You Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=93645#problem/G Description http://7xjob4.com1.z0.glb.clouddn.com/76e435d3c21fa3cbeef1e76780086dc4 Input   Output Sample In…
回文树,也叫回文自动机,是2014年被西伯利亚民族发明的,其功能如下: 1.求前缀字符串中的本质不同的回文串种类 2.求每个本质不同回文串的个数 3.以下标i为结尾的回文串个数/种类 4.每个本质不同回文串包含的本质不同回文串种类 (本文参考自Palindromic Tree——回文树[处理一类回文串问题的强力工具],Palindromic Tree 回文自动机-回文树 解决回文串的神器) 下面介绍一些数组的意义 next[][]类似于字典树,指向当前字符串在两段同时加上一个字符 fail[]…
The Problem to Slow Down You Problem's Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=141572 Mean: 给你两个字符串,求这两个字符串相同回文串的匹配对数. analyse: 每个字符串建一棵回文树,分别从0结点和1结点两棵树一起往下dfs,对于同一条路径上的结点,一定是相同的回文,然后两个的数量相乘加到answer中. Time complexity: O(N)…
回文树 Palindromic Tree 嗯..回文树是个什么东西呢. 回文树(或者说是回文自动机)每个节点代表一个本质不同的回文串. 首先它类似字典树,每个节点有SIGMA个儿子,表示对应的字母. 其次它类似自动机,有一个fail指针,一个节点的fail指针指向这个回文串的最长回文后缀.比如说abbaabba的fail指向abba的最后一个a. 利用回文树,我们可以在线性(不太确定是线性还是\(nlogn\)?)的时间内求出所有本质不同的回文子串,以及以每个字母结尾的最长回文子串. 有一个定理…
The Problem to Slow Down You Time Limit: 20000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Original ID: 100548G64-bit integer IO format: %I64d      Java class name: (Any)   After finishing his homework, our problem setter F…
The Problem to Slow Down You 输入:t个测试样例,每个样例输入两个字符串 输出:这两对字符串的回文串可以组成多少对本质不同的回文串 题意:给你两个字符串,然后问你这两字符串中 有多少对本质不同的字符串子序列 #include<iostream> #include<stdio.h> #include <algorithm> #include <string> #include<string.h> #include<…
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5053 先把第一个串插入回文树中,然后把s数组清空插入第二个串,统计两个cnt数组,答案是二者相乘的结果 #include <iostream> #include <stdlib.h> #include <algorithm> #…
Problem E. TeaTree Problem Description Recently, TeaTree acquire new knoledge gcd (Greatest Common Divisor), now she want to test you. As we know, TeaTree is a tree and her root is node 1, she have n nodes and n-1 edge, for each node i, it has it's v…
https://vjudge.net/problem/UVALive-7041 题意 给出两个仅包含小写字符的字符串 A 和 B : 求:对于 A 中的每个回文子串,B 中和该子串相同的子串个数的总和. 分析 从0和1两个根节点DFS下去,如果两个相同的节点同时存在就统计答案. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <st…
Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. Example: Input: The root of a Binary Search Tree like thi…
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be represented by empty parenthesis pair "()". And you need to omit all the empty parenthesis pairs t…
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 leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7…
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary…
Given a n-ary 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 leaf node. For example, given a 3-ary tree: We should return its max depth, which is 3. Note: The dept…
Problem 2082 过路费 Accept: 382    Submit: 1279 Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description 有n座城市,由n-1条路相连通,使得随意两座城市之间可达.每条路有过路费,要交过路费才干通过.每条路的过路费常常会更新,现问你,当前情况下,从城市a到城市b最少要花多少过路费. Input 有多组例子,每组例子第一行输入两个正整数n,m(2 <= n<=50000,1&…
题目链接 \(Description\) 给定两个串\(S,T\),求两个串有多少对相同回文子串. \(|S|,|T|\leq 2\times 10^5\). \(Solution\) 好菜啊QAQ 这都没想到 对两个串分别建回文树,两个串有相同的回文串当且仅当存在相同的节点. 所以分别从两棵树的两个根(\(0\)和\(1\))DFS,只走两棵树相同的节点,把经过节点的贡献加上就行了. 不要求本质不同,所以要更新一次val[fail[x]]. 把两个串用'$'接成一个串,直接建\(PAM\),分…
http://blog.csdn.net/u013368721/article/details/42100363  回文树 建立两棵回文树,然后count处理一遍就可以了,然后顺着这两棵树的边走下去就好了 #include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <cstdio> using namespace std; ; ;…
依然是回文树. 我们只需要吧siz[]改成统计两边的siz[][0/1],然后把两个字符中间随便加一个不会出现的字符拼起来,做一遍回文树统计一下就OJBK了 #include<bits/stdc++.h> #define ll unsigned long long using namespace std; const int maxn=500005; int T,n,len[maxn],sum[maxn][2],zt,m,p; int ch[maxn][27],fl[maxn],cnt,now…
题意:求两个串的公共回文子串个数 题解:建两个回文自动机,从0和1各跑一边就是答案了,因为对于回文自动机来说,从头开始dfs就能找出该字符串的所有回文串 //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize(4) //#pragma GCC optimize("unroll-loops") //#pragma comment(linker, "/stack:200000000&qu…
Problem E. Split The Tree Problem Description You are given a tree with n vertices, numbered from 1 to n. ith vertex has a value wi We define the weight of a tree as the number of different vertex value in the tree. If we delete one edge in the tree,…
June 8, 2015 我最喜欢的一道算法题目, 二行代码. 编程序需要很强的逻辑思维, 多问几个为什么, 可不可以简化.想一想, 二行代码, 五分钟就可以搞定; 2015年网上大家热议的 Homebrew 的作者 Max Howell 面试 Google 挂掉的一题, 二叉树反转, 七行代码, 相比二行代码, 情有可原! Problem: return the count of binary tree with only one child 想一想, 你要写几行, 六七行, 或小于十行? S…
D. Alyona and a tree Problem Description: Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the girl wrote a positive integer to every edg…
D Tree Problem Description   There is a skyscraping tree standing on the playground of Nanjing University of Science and Technology. On each branch of the tree is an integer (The tree can be treated as a connected graph with N vertices, while each br…
B. Alyona and a tree 题目连接: http://codeforces.com/contest/739/problem/B Description Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote ai. Moreover, the g…
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positiv…
Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the weight. Your task is to deal with M operations of 4 types: 1.Delete an edge (x, y) from the tree, and then add a…
Problem: Given a non-empty binary search tree and a target value, find k values in the BST that are closest to the target. Note: Given target value is a floating point. You may assume k is always valid, that is: k ≤ total nodes. You are guaranteed to…
Problem Description   The picture indicates a tree, every node has 2 children.  The depth of the nodes whose color is blue is 3; the depth of the node whose color is pink is 0.  Now out problem is so easy, give you a tree that every nodes have K chil…
Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2968    Accepted Submission(s): 507 Problem Description You are given a tree (an acyclic undirected connected graph) with N nodes. The tree…