Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's.注意:二...
分类:
其他好文 时间:
2015-04-07 23:01:50
阅读次数:
122
从今天起,模仿《从零单排》系列,菜鸡单刷LeetCode!...
分类:
其他好文 时间:
2015-04-07 21:51:12
阅读次数:
129
uva 10304 Optimal Binary Search Tree题目大意:给出N个结点(已知每个结点的权值)来建树,建树时要满足以下规则:左子树的节点的值要全小于父节点,右子树的节点的值要全大于父节点。要求最后建出的树总权值最小。总权值=各结点乘以层数(从0层开始)之后相加的和。解题思路:dp[i][j]dp[i][j]代表区间第i个结点到第j个结点组成的树最小的总权值。dp[j][i]=m...
分类:
其他好文 时间:
2015-04-07 21:47:33
阅读次数:
127
题意:给你地图‘X’是墙,‘.’是路,和两只公母企鹅的坐标,开始两只企鹅不会在墙里。他们如果没被困,或者没走到地图边缘,或者没被墙挡住,那么都是同时走的,上下同相走,左右反向走。求同时走到H点的最小时间。同时走耗时5s。图里有蜘蛛网‘O’,如果有一只被困,那么另一只可能是笨企鹅,也可能是聪明的企鹅,聪明的走一步耗时2s,笨的3s。如果一只企鹅走到另一只企鹅的旁边,可以把另一只救出来,让他到自己的位置。耗时11s。
两只企鹅如果都被困,就失败了。
做法:
bfs,因为不知道哪只是笨的,所以要bfs两次。打...
分类:
其他好文 时间:
2015-04-07 21:43:49
阅读次数:
142
Mountain Subsequences
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees and flowers on the ...
分类:
其他好文 时间:
2015-04-07 21:42:24
阅读次数:
141
fstream(const char* filename, ios::openmode);ios::app: 以追加的方式打开文件ios::ate: 文件打开后定位到文件尾,ios:app就包含有此属性ios::binary: 以二进制方式打开文件,缺省的方式是文本方式。两种方式的区...
分类:
其他好文 时间:
2015-04-07 19:02:03
阅读次数:
87
这5道题都是array的binary search就可以搞定了
分别是leetcode(35)——Search
Insert Position leetcode(33)——Search
in Rotated Sorted Array leetcode(81)——Search
in Rotated Sorted Array II leetcode(34)——Search
fo...
分类:
其他好文 时间:
2015-04-07 15:38:47
阅读次数:
103
Reverse Bits
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in b...
分类:
其他好文 时间:
2015-04-07 15:37:12
阅读次数:
95
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.
Calling next() will return the next smallest number in the BST.
Note: next()...
分类:
其他好文 时间:
2015-04-07 13:55:03
阅读次数:
116
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....
分类:
其他好文 时间:
2015-04-07 11:59:15
阅读次数:
128