
算法分析
liuyh73
这个作者很懒,什么都没留下…
展开
-
leetcode--46.Permutations题解
题目Given a collection of distinct integers, return all possible permutations. Example:Input:[1,2,3]Output:[ [1,2,3], [2,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]思路...原创 2018-09-09 16:40:01 · 544 阅读 · 0 评论 -
leetcode | 87. Scramble String
题目Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”: great / \ gr ...原创 2018-11-04 16:23:14 · 219 阅读 · 0 评论 -
leetcode | 97. Interleaving String
题目Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.Example 1:Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"Output: trueExample 2:Input: s1 = "aabcc", s2 = "dbb...原创 2018-11-04 17:39:39 · 182 阅读 · 0 评论 -
leetcode | 115. Distinct Subsequences
题目Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (...原创 2018-11-08 21:41:39 · 238 阅读 · 0 评论 -
leetcode | 123. Best Time to Buy and Sell Stock III
题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note: You may not ...原创 2018-11-18 21:52:25 · 536 阅读 · 0 评论 -
leetcode | 45. Jump Game II
题目Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is t...原创 2018-11-18 22:40:27 · 169 阅读 · 0 评论 -
leetcode | 132. Palindrome Partitioning II
题目Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.Example:Input: "aab"Output: 1Explanat...原创 2018-11-24 16:21:39 · 256 阅读 · 0 评论 -
leetcode | 152. Maximum Product Subarray
题目Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] h...原创 2018-11-24 20:26:03 · 191 阅读 · 0 评论 -
leetcode | 57. Insert Interval
题目Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Exam...原创 2018-12-02 20:12:21 · 165 阅读 · 0 评论 -
leetcode | 188. Best Time to Buy and Sell Stock IV
题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most k transactions.Note:You may not en...原创 2018-12-09 14:49:49 · 229 阅读 · 0 评论 -
leetcode | 174. Dungeon Game
题目The demons had captured the princess § and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially po...原创 2018-12-09 18:04:28 · 237 阅读 · 0 评论 -
leetcode | 322. Coin Change
题目You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mon...原创 2018-12-09 18:47:15 · 150 阅读 · 0 评论 -
中国象棋博弈
文章目录棋盘表示着法生成搜索算法最小值-最大值搜索搜索alpha-beta剪枝优化棋局评估棋子子力棋子位置棋盘UI不足参考文献棋盘表示中国象棋的棋盘为10*9的矩形,一般采用10*9的二维数组来表示。chessBoard: [ ["BR1","BN1","BB1","BA1","BK","BA2&原创 2018-12-28 17:26:24 · 4191 阅读 · 0 评论 -
Capacitated Facility Location Problem
文章目录[Problem Description](https://en.wikipedia.org/wiki/Facility_location_problem)[遗传算法(genetic algorithm)](https://en.wikipedia.org/wiki/Genetic_algorithm)基本定义基本流程初始化群体(第一代)适应值函数(evaluate)选择函数(select...原创 2018-12-23 16:18:00 · 1174 阅读 · 0 评论 -
leetcode | 1000. Minmum Cost to Merge Stones
题目There are N piles of stones arranged in a row. The i-th pile has stones[i] stones.A move consists of merging exactly K consecutive piles into one pile, and the cost of this move is equal to the t...原创 2019-03-18 16:57:04 · 672 阅读 · 0 评论 -
leetcode | 64. Minimum Path Sum & 120. Triangle
Minimun Path Sum与120. Triangle题目类似。64. Minimum Path Sum题目Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers alon...原创 2018-11-06 22:45:25 · 189 阅读 · 0 评论 -
leetcode | 63. Unique Paths Ⅱ
题目A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the ...原创 2018-11-06 22:16:16 · 150 阅读 · 0 评论 -
leetcode | 72. Edit Distance
题目Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a characterDelete a char...原创 2018-10-26 15:00:43 · 381 阅读 · 0 评论 -
leetcode--50.Pow(x,n)题解
leetcode–50.Pow(x,n)题解题目Implement pow(x, n), which calculates x raised to the power n (xnxnx^n).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.2...原创 2018-09-09 17:30:47 · 283 阅读 · 0 评论 -
leetcode--310. Minimum Height Trees题解
题目For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum height are called m...原创 2018-09-23 15:06:15 · 718 阅读 · 0 评论 -
leetcode--41. First Missing Positive题解
题目:原创 2018-09-13 16:44:26 · 194 阅读 · 0 评论 -
leetcode--42. Trapping Rain Water题解
题目Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by ...原创 2018-09-13 17:03:13 · 204 阅读 · 0 评论 -
leetcode--802. Find Eventual Safe States题解
题目In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. If we reach a node that is terminal (that is, it has no outgoing directed edges), we stop.Now, ...原创 2018-09-30 21:40:18 · 187 阅读 · 0 评论 -
leetcode--332. Reconstruct Itinerary题解
题目Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus,...原创 2018-10-02 19:38:59 · 346 阅读 · 0 评论 -
leetcode--785. Is Graph Bipartite?
问题Given an undirected graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it’s set of nodes into two independent subsets A and B such that every edge i...原创 2018-10-06 18:05:38 · 440 阅读 · 0 评论 -
leetcode | 684. Redundant Connection
题目In this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N), with one additi...原创 2018-10-15 14:33:13 · 324 阅读 · 0 评论 -
leetcode--839. Similar String Groups题解
题目Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it equals Y.For example, “tars” and “rats” are similar (swapping at positions 0 and 2), and “rats”...原创 2018-09-30 19:53:33 · 530 阅读 · 0 评论 -
leetcode--207.Course Schedule
问题There are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pa...原创 2018-10-14 18:17:08 · 282 阅读 · 0 评论 -
leetcode | 685. Redundant Connection Ⅱ
题目In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, ex...原创 2018-10-19 21:58:25 · 342 阅读 · 0 评论 -
leetcode | 765. Couples Holding Hands
题目N couples sit in 2N seats arranged in a row and want to hold hands. We want to know the minimum number of swaps so that every couple is sitting side by side. A swap consists of choosing any two peo...原创 2018-10-20 20:28:55 · 324 阅读 · 0 评论 -
leetcode | 95. Unique Binary Search Trees Ⅱ
题目Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n.Example:Input: 3Output:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], [2,1,3],...原创 2018-10-20 22:38:06 · 212 阅读 · 0 评论 -
leetcode | 32.Longest Valid Parentheses
题目Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: "(()"Output: 2Explanation: The longest valid...原创 2018-10-25 17:58:29 · 150 阅读 · 0 评论 -
矩阵乘法 | 多线程优化加速
在此篇文章中,主要介绍矩阵的传统算法O(N3)O(N^3)O(N3)的并行加速实现,包括pthread、openmp、mpich等。单线程void singleThread(int **matrix1, int **matrix2, int **res1) { int tmp=0, i, j, k; for(i=0;i<M;i++) { for(k=0;k<P;k++) {...原创 2019-04-03 23:57:03 · 3112 阅读 · 1 评论