其实用不上树链剖分也行,就普通的lca题目 但是经过这道题可以看出树链剖分也可以解决LCA的题目, 注意ptn是dfn的反查,这样能够快速得到dfs序中相应的节点 ...
分类:
其他好文 时间:
2020-02-05 13:33:50
阅读次数:
51
编写一个程序,找出第 n 个丑数。 丑数就是只包含质因数 2, 3, 5 的正整数。 说明: 1 是丑数。 n 不超过1690。 来源:力扣(LeetCode) 链接:https://leetcode cn.com/problems/ugly number ii 1.暴力(brute force) ...
分类:
其他好文 时间:
2020-02-05 11:50:20
阅读次数:
55
Count on a tree II(luogu) Description 题目描述 给定一个n个节点的树,每个节点表示一个整数,问u到v的路径上有多少个不同的整数。 输入格式 第一行有两个整数n和m(n=40000,m=100000)。 第二行有n个整数。第i个整数表示第i个节点表示的整数。 在接 ...
分类:
其他好文 时间:
2020-02-05 11:45:07
阅读次数:
58
We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string, we ...
分类:
其他好文 时间:
2020-02-04 10:24:21
阅读次数:
67
题:https://ac.nowcoder.com/acm/contest/4010/K 题意:用一些模式串凑成一个目标串,每个模式串有消耗,问组合的最小消耗,或不能组成输出-1; 分析:典型的AC自动机处理后在跳fail的过程中进行操作,这里操作就是dp计算最小。用dp[i]表示长串前ii位的最小 ...
分类:
其他好文 时间:
2020-02-04 00:46:26
阅读次数:
65
90. Subsets II Given a collection of integers that might contain duplicates, nums , return all possible subsets (the power set). Note : The solution s ...
分类:
其他好文 时间:
2020-02-04 00:42:05
阅读次数:
78
```go func T(){ //ii, err := fmt.Scanf("%d--%s", &age, &Names) //ii, err := fmt.Scanf("%d--%s\n", &age, &Names) //输入格式为: int--str ii, err := fmt.Scanf... ...
分类:
其他好文 时间:
2020-02-03 18:58:53
阅读次数:
64
链接: "LeetCode667" 给定两个整数?n?和?k,你需要实现一个数组,这个数组包含从?1?到?n?的 n?个不同整数,同时满足以下条件: ① 如果这个数组是$[a1, a2, a3, ... , an]$,那么数组$[|a1 a2|, |a2 a3|, |a3 a4|, ... , |a ...
分类:
其他好文 时间:
2020-02-03 12:19:52
阅读次数:
65
用了前缀集合,高级的可以用前缀树 class Solution: def findWords(self, board: List[List[str]], words: List[str]) -> List[str]: if len(board) == 0 or len(board[0]) == 0: ...
分类:
其他好文 时间:
2020-02-03 09:45:19
阅读次数:
90
一、快慢指针: leedcode 142. 环形链表 II 快慢指针的思想是设置慢指针slow和快指针fast,slow每次走一步,fast每次走两步,如果有环fast指针和slow指针必然相遇,相遇时 定义新的指针p从head开始和slow从当前位置起每次都走一步,直到相遇,相遇的位置就是环的入口 ...
分类:
编程语言 时间:
2020-02-02 22:02:24
阅读次数:
127