2013年10月10日

(转)动态规划 - 最大子数组和(最大子序列和 | 连续子数组最大和)

摘要: 原文作者:Yx.Ac 文章来源:勇幸|Thinking(http://www.ahathinking.com) DP方案考虑DP求解。这个问题可以继续像LCS、LIS一样,“从后向前”分析(《编程之美》对此又是从前向后分析的,个人不太习惯)。我们考虑最后一个元素arr[n-1]与最大子数组的关系,有如下三种情况:arr[n-1]单独构成最大子数组最大子数组以arr[n-1]结尾最大子数组跟arr[n-1]没关系,最大子数组在arr[0-n-2]范围内,转为考虑元素arr[n-2]从上面我们可以看出,问题分解成了三个子问题,最大子数组就是这三个子问题的最大值,现假设:以arr[n-1]为结尾的最 阅读全文

posted @ 2013-10-10 21:40 haoyancoder 阅读(281) 评论(0) 推荐(0)

2013年10月6日

Algorithms - Priceton - 02 - 3-Sum

摘要: 3-Sum : Given N distinct integers, how many triples sum to exactly zero?---------------------------------------------------------------------------------------3-Sum : brute-force algorithm O(N3)---------------------------------------------------------------------------------------3-Sum : sorting-bas 阅读全文

posted @ 2013-10-06 21:32 haoyancoder 阅读(133) 评论(0) 推荐(0)

Algorithms - Priceton - 01 - Dynamic Connectivity & Union Find

摘要: Connected components : Maximal set of objects that are mutually connected.Find query : Check if two objects are in the same component.Union command : Replace components containing two objects with their union.------------------------------------------------------------------------------------------- 阅读全文

posted @ 2013-10-06 15:48 haoyancoder 阅读(192) 评论(0) 推荐(0)

2013年8月18日

coursera review---algorithms,Stanford---04---BFS & DFS

摘要: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 typedef map > graphType; 9 10 void BFS(graphType graph, int starter, map & visitTime) {11 queue Q;12 Q.push(starter);13 map visited;14 for (auto i : graph) {15 visited[i.first] = false;16 }17 ... 阅读全文

posted @ 2013-08-18 10:19 haoyancoder 阅读(178) 评论(0) 推荐(0)

2013年8月17日

coursera review---algorithms,Stanford---03---master method

摘要: the master methodprovides a cookbook solution inasymptoticterms (usingBig O notation) forrecurrence relationsof types that occur in theanalysisof manydivide and conquer algorithmsthe following is the simplified expression:a = number of recursive calls,(>=1)b = input size shrink factor,(>1)d = 阅读全文

posted @ 2013-08-17 16:38 haoyancoder 阅读(384) 评论(0) 推荐(0)

coursera review---algorithms,Stanford---02---quick sort

摘要: the idea of quick sort is:choose a pivot(randomly or simply)partition the array into a[0,1,...,pivot-1],a[pivot],a[pivot+1,...,end] that all elements ina[0,1,...,pivot-1] = a[pivot]quick sorta[0,1,...,pivot-1]quick sorta[pivot+1,...,end] 1 void swap(int a[], int i, int j) { 2 int temp = a[i]; 3 ... 阅读全文

posted @ 2013-08-17 16:20 haoyancoder 阅读(248) 评论(0) 推荐(0)

big number multiplication---straightforward method---not Karatsuba

摘要: input: string a, string boutput : a string that denotes a times b 1 #include 2 3 string mul(const string & a, const string & b) { 4 int al = a.length(); 5 int bl = b.length(); 6 int *result = new int[al + bl]; 7 for (int i = 0; i = 0; i--) {17 if (result[i] >= 10) {18 ... 阅读全文

posted @ 2013-08-17 11:29 haoyancoder 阅读(184) 评论(0) 推荐(0)

2013年8月16日

coursera review---algorithms,Stanford---01---merge sort

摘要: merge sort is a typical divide & conquer algorithm,merge is this algorithm's core subroutine,merge:merge two sorted subarrays into one sorted arraymergeSort:divide input array to two subarrays leftArray and rightArraymergeSort(leftArray);mergeSort(rightArray);merge these two subarrays 1 // m 阅读全文

posted @ 2013-08-16 22:21 haoyancoder 阅读(212) 评论(0) 推荐(0)

2013年8月14日

coursera

摘要: Machine Learning------Andrew Ng------Stanford University------https://www.coursera.org/course/mlAlgorithms:Design and Analysis,Part 1------Tim Roughgarden------Stanford University------https://www.coursera.org/course/algoCoding the Matrix:Linear Algebra through Computer Science Applications------Phi 阅读全文

posted @ 2013-08-14 22:26 haoyancoder 阅读(196) 评论(0) 推荐(0)

导航