上一页 1 2 3 4 5 6 7 8 9 ··· 18 下一页
摘要: 题目描述:一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。输入:输入可能包含多个测试样例,对于每个测试案例,输入包括一个整数n(1<=n<=50)。输出:对应每个测试案例,输出该青蛙跳上一个n级的台阶总共有多少种跳法。样例输入:6样例输出:32又是斐波纳妾的变种 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 long long f[52]; 7 f[1] = 1; 8 9 for(int i = 2; i <= 50; 阅读全文
posted @ 2012-11-21 12:07 chkkch 阅读(614) 评论(0) 推荐(0) 编辑
摘要: 题目描述:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。输入:输入可能包含多个测试样例,对于每个测试案例,输入包括一个整数n(1<=n<=70)。输出:对应每个测试案例,输出该青蛙跳上一个n级的台阶总共有多少种跳法。样例输入:5样例输出:8Fibonacci的变形 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 long long f[71]; 7 8 f[0] = 1; 9 f[1] = 1;10 11 for(int i... 阅读全文
posted @ 2012-11-21 12:02 chkkch 阅读(411) 评论(0) 推荐(0) 编辑
摘要: 题目描述:大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。斐波那契数列的定义如下:输入:输入可能包含多个测试样例,对于每个测试案例,输入包括一个整数n(1<=n<=70)。输出:对应每个测试案例,输出第n项斐波那契数列的值。样例输入:3样例输出:2 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 long long f[71]; 7 8 f[0] = 0; 9 f[1] = 1;10 11 for(int i = 2; i <= ... 阅读全文
posted @ 2012-11-21 11:59 chkkch 阅读(375) 评论(0) 推荐(0) 编辑
摘要: 题目描述:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并输出它的后序遍历序列。输入:输入可能包含多个测试样例,对于每个测试案例,输入的第一行为一个整数n(1<=n<=1000):代表二叉树的节点个数。输入的第二行包括n个整数(其中每个元素a的范围为(1<=a<=1000)):代表二叉树的前序遍历序列。输入的第三行包括n个整数(其中每个元素a的范围为(1<=a<=1000)):代 阅读全文
posted @ 2012-11-21 11:30 chkkch 阅读(599) 评论(0) 推荐(0) 编辑
摘要: 题目描述:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。输入:输入可能包含多个测试样例,对于每个测试案例,输入的第一行为两个整数m和n(1<=m,n<=1000):代表将要输入的矩阵的行数和列数。输入的第二行包括一个整数t(1<=t<=1000000):代表要查找的数字。接下来的m行,每行有n个数,代表题目所给出的m行n列的矩阵(矩阵如题目描述所示,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。输出:对应每个测试案例,输出”Y 阅读全文
posted @ 2012-11-21 11:07 chkkch 阅读(4965) 评论(0) 推荐(0) 编辑
摘要: Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf no... 阅读全文
posted @ 2012-11-19 22:16 chkkch 阅读(2190) 评论(0) 推荐(0) 编辑
摘要: Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/http://www.cnblogs.com/c/", =>"/c"Corner Cases:Did you consider the case wherepath="/../"?In this case, you should return"/". 阅读全文
posted @ 2012-11-19 21:13 chkkch 阅读(1959) 评论(0) 推荐(0) 编辑
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?这题用O(n)的辅助空间比较好做,中序遍历后排个序O(nlogn)。但要不改变树的结构来完成就比较难了。我只能想到一个把bst转为double link list后 阅读全文
posted @ 2012-11-19 19:50 chkkch 阅读(2550) 评论(1) 推荐(0) 编辑
摘要: Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 unique BST's shown below. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ ... 阅读全文
posted @ 2012-11-19 19:20 chkkch 阅读(4879) 评论(0) 推荐(1) 编辑
摘要: 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. 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 ... 阅读全文
posted @ 2012-11-19 17:34 chkkch 阅读(1009) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 18 下一页