题意,一颗树,每个边有个值,在树上找一条简单路径,使得这条路径上的边权异或值最大
把这题模型转换一下, 对于任意一条路径的异或,表示为f(u, v)
则f(u, v) = f(1, u) ^ f(1, v)
这是显然的
其中f(1, i)是可以再O(n)内处理出来
然后就是在一个数组内,找两个数异或值最大
然后就可以用字典树来搞
每个数变成01串, 然后插入字典树,...
分类:
其他好文 时间:
2015-01-22 23:24:23
阅读次数:
192
https://oj.leetcode.com/problems/longest-palindromic-substring/Given a stringS, find the longest palindromic substring inS. You may assume that the ma...
分类:
其他好文 时间:
2015-01-22 17:24:11
阅读次数:
105
Given a string, find the length of the longest substring T that contains at most 2 distinct characters.For example, Given s = “eceba”,T is "ece" which...
分类:
其他好文 时间:
2015-01-22 14:52:17
阅读次数:
134
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes...
分类:
其他好文 时间:
2015-01-22 00:10:52
阅读次数:
142
原题地址1. 把所有元素都塞到集合里2. 遍历所有元素,对于每个元素,如果集合里没有,就算了,如果有的话,就向左向右拓展,找到最长的连续范围,同时在每次找的时候都把找到的删掉。这样做保证了同样的连续序列只会被遍历一次,从而保证时间复杂度。时间复杂度O(n)代码: 1 int longestConse...
分类:
其他好文 时间:
2015-01-20 17:29:55
阅读次数:
126
【题目】
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without
repeating letters for "abcabcbb" is "abc", which the length is...
分类:
其他好文 时间:
2015-01-20 15:42:24
阅读次数:
132
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest-common-prefix/14: Longest Common PrefixWrite a fu...
分类:
编程语言 时间:
2015-01-19 20:39:03
阅读次数:
205
https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/Given a string, find the length of the longest substring without repea...
分类:
其他好文 时间:
2015-01-18 23:57:54
阅读次数:
264
题目:
Given a string, find the length of the longest substring without repeating characters. For example,
the longest substring without repeating letters for "abcabcbb" is "abc", which the length is ...
分类:
编程语言 时间:
2015-01-17 18:10:44
阅读次数:
251
最长公共子序列时间限制:3000 ms | 内存限制:65535 KB 难度:3描述咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列。tip:最长公共子序列也称作最长公共子串(不要求连续),英文缩写为LCS(Longest Common Subsequence)。其定义是,一个...
分类:
其他好文 时间:
2015-01-16 16:00:46
阅读次数:
145