
算法设计
文章平均质量分 72
Vinson
梦想路上,全力以赴,顺其自然......
展开
-
【转】那些年使用过MapReduce的论文
MapReduce is a programming model for processing large data sets with a parallel, distributed algorithm on a cluster. It's definitely based on the principle of divide-and-conquer method. A MapRe...原创 2014-03-09 15:20:26 · 530 阅读 · 0 评论 -
Combination Sum(c++实现)
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number...2013-07-10 16:20:46 · 149 阅读 · 0 评论 -
【DP_树形DP专辑】【9月9最新更新】
转自:http://blog.youkuaiyun.com/woshi250hua/article/details/7644959 树,一种十分优美的数据结构,因为它本身就具有的递归性,所以它和子树见能相互传递很多信息,还因为它作为被限制的图在上面可进行的操作更多,所以各种用于不同地方的树都出现了,二叉树、三叉树、静态搜索树、AVL树,线段树、SPLAY树,后缀树等等.. 枚举那么多种数...原创 2013-06-10 15:11:43 · 115 阅读 · 0 评论 -
Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false...2013-06-08 18:28:22 · 107 阅读 · 0 评论 -
Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ ...2013-06-08 14:24:35 · 90 阅读 · 0 评论 -
Word Search (C++)
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically...2013-06-05 21:49:01 · 137 阅读 · 0 评论 -
Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]] class Solution {pub...2013-06-04 12:11:01 · 84 阅读 · 0 评论 -
Morris traversal: traverse binary tree inorder with no recursion and O(1) space
参考:http://pthread.blog.163.com/blog/static/169308178201210112045787/ Most textbooks mention that binary tree can be traversed using recursion or , using stack without recursion. The recursive pro...原创 2013-06-03 15:31:59 · 108 阅读 · 0 评论 -
Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ...2013-05-29 05:11:03 · 95 阅读 · 0 评论 -
Remove Duplicates from Sorted List II (C++)
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: L...原创 2013-05-29 05:10:24 · 90 阅读 · 0 评论 -
用全排列的方式生成一个数列的随机排列(C++实现)
Question: input : n output: A random permutation of [0 .. n-1] ie: input: 5output: 0 3 2 4 1 // Type your C++ code and click the "Run Code" button!// Your code outpu...2013-05-28 23:44:29 · 918 阅读 · 0 评论 -
Rotate List (C++)
Question: Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NU...2013-05-28 00:09:44 · 139 阅读 · 0 评论 -
Best Time to Buy and Sell Stock I
question: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one shar...2013-05-27 16:41:12 · 92 阅读 · 0 评论 -
Combination Sum II(c++实现)
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combin...2013-07-10 16:32:47 · 169 阅读 · 0 评论 -
Combinations(c++实现)
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [...2013-07-10 16:52:29 · 535 阅读 · 0 评论 -
subsets(C++实现)
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets. For exampl...2013-07-13 23:15:47 · 396 阅读 · 0 评论 -
【转】基数排序
转自:http://www.cppblog.com/shongbee2/archive/2009/04/24/80992.html 今天学了基数排序,据说他的时间复杂度也是O(n),他的思路就是:没有计数排序那么理想,我们的数据都比较集中,都比较大,一般是4,5位。基本没有小的数据。那我们的处理很简单,你不是没有小的数据嘛。我给一个基数,例如个位,个位都是[0-10)范围内的。先对他进行...原创 2013-09-20 22:42:55 · 115 阅读 · 0 评论 -
字符串题目推荐及解题报告
转自:http://hi.baidu.com/fpkelejggfbfimd/item/701ab1be964e89d184dd79a6 POJ 1002 - 487-3279(基础)http://acm.pku.edu.cn/JudgeOnline/problem?id=1002题意:略解法:二叉查找数,map,快排...POJ 1200 - Crazy Search(基础)ht...原创 2013-09-08 17:30:31 · 183 阅读 · 0 评论 -
循环字符串最小表示
题目 From POJ : http://poj.org/problem?id=1509 #include <iostream>#include <string>using namespace std;int minlist(string &str) { if(str.size() < 2) return 0; ...2013-09-07 20:29:38 · 138 阅读 · 0 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a pali...2013-07-29 10:34:04 · 98 阅读 · 0 评论 -
Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX X ...2013-07-28 20:11:31 · 111 阅读 · 0 评论 -
Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. /** * Definition for binary tree * struct TreeNo...2013-07-27 21:11:25 · 117 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. // construct tree from preorder and inorder class...2013-07-27 13:58:36 · 97 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". class Solution {public: string addBinary(string a, string b) { if(a.s...2013-07-23 00:59:28 · 126 阅读 · 0 评论 -
Best Time to Buy and Sell Stock I II III(C++实现)
// Best Time to Buy and Sell Stock I class Solution {public: int maxProfit(vector<int> &prices) { if(prices.size() < 2) return 0; int mj = 0, mjIdx = 0; ...2013-07-20 20:10:41 · 132 阅读 · 0 评论 -
4Sum (C++实现)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: Elements...2013-12-12 19:07:48 · 361 阅读 · 0 评论 -
Merge Sort (C++ 实现)
// Type your C++ code and click the "Run Code" button!// Your code output will be shown on the left.// Click on the "Show input" button to enter input data to be read (from stdin).#include &...2013-07-14 16:01:31 · 339 阅读 · 0 评论 -
Subsets II(C++实现)
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dup...2013-07-13 23:16:54 · 138 阅读 · 0 评论 -
Longest Consecutive Sequence (C++实现)
class Solution {public: int longestConsecutive(vector<int> &num) { int n = num.size(); if(n <= 0) return 0; if(n == 1) return 1; sor...2013-05-27 16:37:26 · 123 阅读 · 0 评论 -
Surrounded Regions (C++实现)
#define TEMP_FLAG 'Z'#define O_FLAG 'O'#define X_FLAG 'X'class Solution {public: void solve(vector<vector<char>> &board) { int m = board.size(); ...2013-05-26 19:50:41 · 134 阅读 · 0 评论 -
Sum Root to Leaf Numbers
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */c...原创 2013-05-26 15:02:49 · 84 阅读 · 0 评论 -
二叉树层次遍历C++实现
// Type your C++ code and click the "Run Code" button!// Your code output will be shown on the left.// Click on the "Show input" button to enter input data to be read (from stdin). #include ...原创 2013-05-13 10:00:48 · 122 阅读 · 0 评论 -
使用多线程的利弊
参考:http://software.intel.com/zh-cn/blogs/2013/04/09/?utm_campaign=优快云&utm_source=intel.youkuaiyun.com&utm_medium=Link&utm_content=%20Multicore%20-duoxiancheng 1. Amdahl定律 一个很简单的量化公式,...原创 2013-05-10 23:44:52 · 93 阅读 · 0 评论 -
层层遍历树
// ---------------------- 层层遍历树 ------------------------ //// 笨方法typedef struct Node { int val; struct Node *left; struct Node *right;} TNode;static TNode root;void ...原创 2013-05-10 22:54:20 · 144 阅读 · 0 评论 -
最长公共子序列 与 最长子序列 (C++实现)
// Type your C++ code and click the "Run Code" button!// Your code output will be shown on the left.// Click on the "Show input" button to enter input data to be read (from stdin).#include &l...2013-05-09 18:00:59 · 225 阅读 · 0 评论 -
判断一棵树是否对称(C实现)
// Type your C++ code and click the "Run Code" button!// Your code output will be shown on the left.// Click on the "Show input" button to enter input data to be read (from stdin). #include &...2013-05-07 13:52:45 · 170 阅读 · 0 评论 -
自学算法之路
现在真的在自学算法,努力按照以下阶段复习中,争取做到倒背如流首先,先介绍两本算法书:1.<Introduction to Algorithms>,这本是算法最 经典教材,几乎所有学习算法都用的这本书。2.<Mastering Algorithms with Perl>,因为本人极度喜欢Perl,所以推荐这本书,内容也不错。以下归入正题:第一阶段:练经典常用...原创 2012-11-16 10:25:27 · 150 阅读 · 0 评论 -
【转】模拟退火算法浅析
转自:http://www.cnblogs.com/heaad/archive/2010/12/20/1911614.html 一. 爬山算法 ( Hill Climbing ) 介绍模拟退火前,先介绍爬山算法。爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解。 爬山算法实现很简...原创 2012-11-14 15:43:55 · 83 阅读 · 0 评论 -
[转]贝叶斯球(Bayes Ball)算法
参考:http://www.cnblogs.com/pangliang/archive/2011/02/27/1966303.html 用有向图表示的概率模型也叫“贝叶斯网络”. 贝叶斯网络中的两个结点与关于结点(或结点集合)条件独立时我们称“D-separates”与, 写作. D-Separation中的D指Directed. 从图形上看, 结点集合“D-separates”结点...原创 2012-11-12 10:53:17 · 916 阅读 · 0 评论 -
应用动态规划的算法
参考:http://blog.youkuaiyun.com/huanhuolang/article/details/6146770 1) 许多字符串操作算法如最长公共子列、最长递增子列、最长公共字串;2) 将动态规划用于图的树分解,可以有效解决有界树宽图的生成树等许多与图相关的算法问题;3) 决定是否及如何可以通过某一特定上下文无关文法产生给定字符串的Cocke-Younger-Kasa...原创 2012-07-14 11:06:14 · 145 阅读 · 0 评论