Counting Binary Trees
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 564 Accepted Submission(s): 184
Problem Description
There ...
分类:
其他好文 时间:
2014-08-25 17:07:44
阅读次数:
266
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".思路: 1 class Solution { 2 public: 3 strin...
分类:
其他好文 时间:
2014-08-25 16:58:34
阅读次数:
188
Codeforces Round #254 (Div. 2)E题这题说的是给了一个一段连续的区间每个区间有一种颜色然后一个彩笔从L画到R每个区间的颜色都发生了 改变然后 在L和R这部分区间里所用的颜色变成了x 然后每个区间的 色度加上abs(x-Yi) Yi 为原位置的颜色,还有一个操作就是求 L ...
分类:
其他好文 时间:
2014-08-25 16:39:14
阅读次数:
273
HDU 3240 Counting Binary Trees(组合数学-斯特林数,数论-整数快速幂,数论-求逆元)
题目大意:
问你不超过n个节点的二叉树的方案数,结果要对m求余。
解题思路:
方案数可以划分左右两边划分子问题也就是 h(n)=h(0)*h(n-1)+h(1)*(h-2)+..................+h(n-1)*h(0),一看就是卡特兰数,
关于卡特兰数必须要nlg^n的左右效率的算法解决
百度一下,知道:
令h(0)=1,h(1)=1,
catalan数满足:
递推式[1]...
分类:
其他好文 时间:
2014-08-25 14:59:24
阅读次数:
223
UVA 1264 - Binary Search Tree
题目链接
题意:给定一个序列,插入二叉排序树,问有多少中序列插入后和这个树是相同的(包括原序列)
思路:先建树,然后dfs一遍,对于一个子树而言,只要保证左边和右边顺序对就可以了,所以种数为C(左右结点总数,左结点),然后根据乘法原理乘上左右子树的情况即可
代码:
#include
#include
t...
分类:
其他好文 时间:
2014-08-25 11:51:14
阅读次数:
204
转自:http://blog.csdn.net/lalor/article/details/7614381问题定义: You are given a binary tree in which each node contains a value. Design an algorithm to ...
分类:
其他好文 时间:
2014-08-25 11:20:04
阅读次数:
292
Problem 36
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
(Please...
分类:
其他好文 时间:
2014-08-25 10:06:04
阅读次数:
198
class Solution {private: vector nodes;public: void recoverTree(TreeNode *root) { nodes.clear(); dfs(root); // 1 5 3 4 2 6 7...
分类:
其他好文 时间:
2014-08-25 01:07:23
阅读次数:
329