题目链接:点击打开链接
== 原来写1的时候已经把更新函数写好了。。
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define N 50050
#define Lson(x) tree[x].l
#define Rson(x) tree[x].r
...
分类:
其他好文 时间:
2014-08-31 20:08:01
阅读次数:
247
题目链接:点击打开链接
每个点都是最大值,把一整个序列和都压缩在一个点里。
#include
#include
#include
#include
#include
using namespace std;
#define N 100005
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
#define L(x) tre...
分类:
其他好文 时间:
2014-08-31 14:33:31
阅读次数:
169
3871. GCD ExtremeProblem code: GCDEXGiven the value of N, you will have to find the value of G. The meaning of G is given in the following codeG=0;for...
分类:
其他好文 时间:
2014-08-30 12:32:49
阅读次数:
208
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * public class TreeN...
分类:
其他好文 时间:
2014-08-30 01:10:48
阅读次数:
333
题目大意:
给出了N个串。问最多有多少个串组成的序列,是可以由上一个串通过左右两边加字符构成的。
思路分析:
在trie上的dp
在建立自动机的时候,得到fail的同时,用dp记录这个串作为最后一个串所可以得到的最多的满足要求的串的数量。
那么 dp[i] = max(dp[i在trie上的的父亲节点],dp[i的fail节点] )+ 以i节点结尾的单词的数量,注意不是以i字符结...
Problem code: LCMSUMGiven n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i...
分类:
其他好文 时间:
2014-08-28 22:23:56
阅读次数:
347
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.方法:将有序数组转为平...
分类:
其他好文 时间:
2014-08-27 23:17:18
阅读次数:
278
LeetCode: Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a ...
分类:
其他好文 时间:
2014-08-27 21:51:38
阅读次数:
199
思想:先序遍历。注意的是: 当只有一个孩子结点时,深度是此孩子结点深度加 1 .
思想: 先序遍历。既要返回左右子树判断的结果,又要返回左右子树的深度进行再判断。
所以要么返回一个 pair, 要么函数参数增加一个引用来传递返回值。
分类:
其他好文 时间:
2014-08-27 18:25:08
阅读次数:
207
http://acm.hdu.edu.cn/showproblem.php?pid=3709
平衡数。枚举支点的位置,同时记录力臂。
dp[i][j][k]表示当前处理到第i个数,支点的位置是j,当前的力臂是k。因此判断某个数是否是平衡数,只需判断递归终点时力臂是否为0。
#include
#include
#include
#include
#include
#i...
分类:
其他好文 时间:
2014-08-27 14:48:47
阅读次数:
180