Codeforces914E. Palindromes in a Tree】的更多相关文章

n<=100000的树,每个点上有个字母a-t之一,问有多少这样的链经过每个点:它的某一个排列的字母串起来是回文的. 就是有最多一个字母是奇数个啦..这样点分算一波即可..细节较多详见代码 #include<string.h> #include<stdlib.h> #include<stdio.h> #include<math.h> #include<algorithm> //#include<queue> //#include…
[题目]E. Palindromes in a Tree [题意]给定一棵树,每个点都有一个a~t的字符,一条路径回文定义为路径上的字符存在一个排列构成回文串,求经过每个点的回文路径数.n<=2*10^5. [算法]点分治 [题解]状压20位的二进制表示一条路径的字符状态,点分治过程中维护扫描过的路径只须维护状态桶数组,t[i]表示前面状态为i的路径条数. 合并:考虑当前状态为j,要使合并的状态满足条件即i^j=1<<k(0<=k<20)或i^j=0,移项得i=j^(1<…
You are given a tree (a connected acyclic undirected graph) of n vertices. Vertices are numbered from 1 to n and each vertex is assigned a character from a to t. A path in the tree is said to be palindromic if at least one permutation of the labels i…
https://vjudge.net/problem/CodeForces-914E 点分就没一道不卡常的? 卡常记录: 1.把不知道为什么设的(unordered_map)s换成了(int[])s 2.减少一次cal2和clr #pragma GCC optimize("Ofast") #include<cstdio> #include<algorithm> #include<cstring> #include<vector> usin…
$ \color{#0066ff}{ 题目描述 }$ 给你一颗 n 个顶点的树(连通无环图).顶点从 1 到 n 编号,并且每个顶点对应一个在'a'到't'的字母. 树上的一条路径是回文是指至少有一个对应字母的排列为回文. 对于每个顶点,输出通过它的回文路径的数量. 注意:从u到v的路径与从v到u的路径视为相同,只计数一次. \(\color{#0066ff}{输入格式}\) 第一行包含一个整数n(2<=n<=2*10^5). 接下来的 n-1 行,每行包含两个整数u和v(1<=u,v&…
link 题目大意:给定一个n个点的树,每个点都有一个字符(a-t,20个字符) 我们称一个路径是神犇的,当这个路径上所有点的字母的某个排列是回文 求出对于每个点,求出经过他的神犇路径的数量 题解: 对于回文串,我们发现最多允许1个字母出现了奇数次,和%2有关 并且由于只有20个字母,说到20我就想起了二进制状压,我们对于一条链状压成20维的01向量,表示某个字符出现的次数是奇数还是偶数 说到树上静态问题我就想起淀粉质 我们考虑静态淀粉质,对于当前的树我们找出他的重心rt,然后对于每个子树DFS…
题面 洛谷 CF 题解 题意:给你一颗 n 个顶点的树(连通无环图).顶点从 1 到 n 编号,并且每个顶点对应一个在'a'到't'的字母. 树上的一条路径是回文是指至少有一个对应字母的排列为回文. 对于每个顶点,输出通过它的回文路径的数量. 注意:从u到v的路径与从v到u的路径视为相同,只计数一次 性质:回文字符串至多一个字母次数为奇数 因为字母只有'a'~'t' 那么可以状压一下 然后就是套点分治就好了 注意:顶点经过的次数要除以2(因为每条路径算了两次) Code #include<bit…
Tree Palindromes Given a tree rooted at node 1 with N nodes, each is assigned a lower case latin character. Print the sum of length of longest palindrome substring from string generated by simple path from root to all other nodes i.e root to some oth…
树的直径: 利用了树的直径的一个性质:距某个点最远的叶子节点一定是树的某一条直径的端点. 先从任意一顶点a出发,bfs找到离它最远的一个叶子顶点b,然后再从b出发bfs找到离b最远的顶点c,那么b和c之间的距离就是树的直径. 用dfs也可以. 模板: ; int head[N]; int dis[N]; bool vis[N]; ,b,mxn=; struct edge { int to,w,next; }edge[N]; void add_edge(int u,int v,int w) { e…
考试注意事项:link1 link2 (密码:wangle) 调不出来bug,可以先透彻一会儿或者是上个厕所或者坐一会别的题(间隔至少20min),然后通读代码 -1. 考试先读题,读题之后搞出一个做题规划 做一些duliu题,人脑内存不够时,把纸和笔当内存用 不要相信你的人脑内存 /2是向零取整,如果写权值线段树需要开负数下标,那么一定要用>>1而不是/2(这个在FFT上没啥区别,但是开负数下标就GG了)(MloVtry的咸鱼树) upd:会炸int就 (cl + (long long)cr…
D time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Roman planted a tree consisting of n vertices. Each vertex contains a lowercase English letter. Vertex 1 is the root of the tree, each of…
A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 Description Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindro…
2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 Description Dima adds letters s1, -, sn one by one to the end of a word. After each letter, he asks Misha to tell him how many new palindrome substrings a…
Palindromes and Super Abilities 2 Time Limit: 1MS   Memory Limit: 102400KB   64bit IO Format: %I64d & %I64u Status Description Dima adds letters s1, -, sn one by one to the end of a word. After each letter, he asks Misha to tell him how many new pali…
Number of Palindromes Time Limit: 100MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submit Status Description Each palindrome can be always created from the other palindromes, if a single character is also a palindrome. For example, the…
C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un…
题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex…
A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un…
二叉树(Binary Tree)是最简单的树形数据结构,然而却十分精妙.其衍生出各种算法,以致于占据了数据结构的半壁江山.STL中大名顶顶的关联容器--集合(set).映射(map)便是使用二叉树实现.由于篇幅有限,此处仅作一般介绍(如果想要完全了解二叉树以及其衍生出的各种算法,恐怕要写8~10篇). 1)二叉树(Binary Tree) 顾名思义,就是一个节点分出两个节点,称其为左右子节点:每个子节点又可以分出两个子节点,这样递归分叉,其形状很像一颗倒着的树.二叉树限制了每个节点最多有两个子节…
树视图可以用于表示数据的层次. 例如:SAP CRM中的组织结构数据可以表示为树视图. 在SAP CRM Web UI的术语当中,没有像表视图(table view)或者表单视图(form view)那种专门的树视图类型.我们可以认为树视图是表视图的一种特例.因此,没有可以用于创建树视图的向导,需要按以下特定的步骤手动改造已存在的视图. 首先,这个看起来挺难的,但是随着实践次数的增多,你会很容易理解它.在本文,我将创建一个如下模样的树视图. 如你所见,它有两级结构.第一级展示LEAD ID,下一…
无限分级 很多时候我们不确定等级关系的层级,这个时候就需要用到无限分级了. 说到无限分级,又要扯到递归调用了.(据说频繁递归是很耗性能的),在此我们需要先设计好表机构,用来存储无限分级的数据.当然,以下都是自己捣鼓的结果,非标准.谁有更好的设计望不吝啬赐教. 说来其实也简单,就是一个ID和父ID的关系. 以此类推,Id需要是唯一的,ParenId需要是Id列里面存在即可.这样我们就实现无限分级了,如果再加一列Sort排序就更完美了. jstree插件 官方地址:https://www.jstre…
在正文开始之前需要介绍一个人:Sean Sexton. 来自明尼苏达双城的软件工程师.最为出色的是他维护了两个博客:2,000Things You Should Know About C# 和 2,000 Things You Should Know About WPF .他以类似微博式的150字简短语言来每天更新一条WPF和C#重要又容易被遗忘的知识.Follow他的博客也有一段日子了,很希望能够分享给大家. 本系列我不仅会翻译他的每一个tip,也会加入自己开发之中的看法和见解.本系列我希望自…
题目链接:Balanced Binary Tree | LeetCode OJ 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 differ by more tha…
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. Tags: Depth-first Search 分析 很基本的一道深度优…
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a constan…
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right…
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is not: 1 / \ 2 2 \ \ 3 3 Note: B…
指定节点变色 指定节点隐藏 单击节点 未选中则选中该节点 已选中则取消该节点 前台: 1.HTML <ul id="listDept" name="listDept"  data-options="region:'center',border: true"></ul> 2.JS var deptTree = null; $(function() { deptTree = $('#listDept');  initTree(…
构造一棵easyui前台框架的一个树形列表为例后台框架是spring MVC+JPA. 先看一下数据库是怎么建的,怎么存放的数据 下面是实体类 /** * 部门类 用户所属部门(这里的部门是一个相对抽象的词) * 使用前缀编码,每级增加三个数字,如:第一级 001,第二级001001,第三级001001001 * @author Administrator * */ @Entity public class Department { private String id; //部门id priva…
使用cmder确实是方便了很多,想看命令帮助信息: $ help tree 以图形显示驱动器或路径的文件夹结构. TREE [drive:][path] [/F] [/A] /F 显示每个文件夹中文件的名称. /A 使用 ASCII 字符,而不使用扩展字符. 看看区别 扩展字符显示 $ tree work /f 卷 软件 的文件夹 PATH 列表 卷序列号为 000E-E536 D:\APACHE TOMCAT9_X64\WORK └─Catalina ├─boystyle.cn │ ├─doc…