数据结构 | 算法
文章平均质量分 92
DouMiaoO_Oo
这个作者很懒,什么都没留下…
展开
-
编程珠玑读书笔记-第2章
版权声明:本文为 DouMiaoO_Oo 原创文章,未经允许不得转载!转载请注明出处 重点内容旋转数组把一个nnn元一维数组向左旋转(即循环移位)kkk个位置。例如对于nnn=8的数组abcdefg, 当k=3k=3k=3时,通过旋转可以得到defgabcdefgabcdefgabc。类似题目可以参考 LeetCode 189. Rotate Array, 这题是把右边的k个元素交换到左边的位...原创 2019-10-13 17:24:35 · 154 阅读 · 0 评论 -
编程珠玑读书笔记-第1章
编程珠玑,读书总结,心得原创 2019-10-13 17:18:37 · 190 阅读 · 0 评论 -
生成子集 subset
《程序员面试金典》上面的一道题目,leetcode也有这道题返回某集合的所有非空子集。给定一个int数组A和数组的大小int n,请返回A的所有非空子集。保证A的元素个数小于等于20,且元素互异。各子集内部从大到小排序,子集之间字典逆序排序,见样例。测试样例:[123,456,789]返回:{[789,456,123],[789,456],[789,123],[789],[456 123...原创 2019-02-24 00:47:01 · 327 阅读 · 0 评论 -
模拟退火解TSP问题
模拟退火解决TSP问题原创 2017-12-24 21:25:07 · 519 阅读 · 0 评论 -
数据结构总结目录
数据结构总结目录原创 2017-07-10 10:50:48 · 465 阅读 · 0 评论 -
最长公共子序列(LCS)
LCS (Longest Common Subsequence)动态规划方法解法#include <iostream>#include <cstring>#include <sstream>#include <stdio.h>using namespace std;void LCSLength(int m, int n, char *x, char *y , int **c){ /原创 2017-12-03 16:07:11 · 280 阅读 · 0 评论 -
矩阵连乘问题
多个矩阵连乘,给这样的矩阵序列加括号,使乘法的计算次数最小。使用的是动态规划的思想。#include <iostream>#include <string>#include <sstream>using namespace std;void MatrixChain(int n, int *p, int **m, int **s){ /* 找到矩阵链乘法需要的最小乘法次数,以及划原创 2017-12-03 10:56:40 · 397 阅读 · 0 评论 -
全排列生成 permutation
c++ 迭代的方法生成全排列。原创 2017-12-19 20:09:57 · 491 阅读 · 0 评论 -
字符串匹配算法
字符串匹配算法原创 2019-08-10 10:33:33 · 330 阅读 · 0 评论 -
编程珠玑读书笔记-第8章
读书总结,心得,编程珠玑,最大连续子串和,找出连续子串的最大和,动态规划,DP原创 2019-10-14 15:03:13 · 228 阅读 · 0 评论 -
桶排序
排序算法,桶排序,bucket sort原创 2017-07-11 23:59:35 · 331 阅读 · 0 评论 -
插入排序
插入排序#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <vector>using namespace std;void insert_sort(vector<int>& arr){ ...原创 2019-03-02 14:43:28 · 126 阅读 · 0 评论 -
冒泡排序
冒泡排序#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <vector>using namespace std;void bubble_sort(vector<int>& arr){ ...原创 2019-03-02 14:59:52 · 169 阅读 · 0 评论 -
背包问题 (Knapsack problem)
文章目录概述普通01背包,不要求背包恰好装满完全背包参考资料概述给定NNN个物品,每种物品都有自己的重量cic_ici和价值wiw_iwi,现有一个背包,能承受的重量为VVV。在不超过背包容量的限制下放入物品,使得物品的总价值最大。这一类问题,被称为背包问题。普通01背包,不要求背包恰好装满P1048 采药题目描述辰辰是个天资聪颖的孩子,他的梦想是成为世界上最伟大的医师。为此,他想...原创 2019-04-09 17:40:12 · 654 阅读 · 0 评论 -
硬币面值组合 (完全背包)
题目描述有数量不限的硬币,币值为25分、10分、5分和1分,请编写代码计算n分有几种表示法。给定一个int n,请返回n分有几种表示法。保证n小于等于100000,为了防止溢出,请将答案Mod 1000000007。测试样例:6返回:22维dpint countWaysV2(int n) { int coins[] = {0, 1, 5, 10, 25}; ...原创 2019-04-10 19:23:16 · 843 阅读 · 0 评论 -
LeetCode|Maximum Product Subarray
Maximum Product SubarrayGiven 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: ...原创 2019-04-01 13:33:36 · 135 阅读 · 0 评论 -
连续子数组的最大和 (Maximum Subarray)
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subar原创 2019-04-01 12:31:30 · 217 阅读 · 0 评论 -
LeetCode|Super Pow
Super PowSuper PowYour task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.Example 1:Input: a = 2, b = [3]Out...原创 2019-03-31 17:23:04 · 136 阅读 · 0 评论 -
字符串编辑距离
题目描述UNIX系统下有一个行编辑器ed,它每次只对一行文本做删除一个字符、插入一个字符或替换一个字符三种操作。例如某一行的内容是“ABC”,经过把第二个字符替换成“D”、删除第一个字符、末尾插入一个字符“B”,这三步操作后,内容就变成了“DCB”。即“ABC”变成“DCB”需要经过3步操作,我们称它们的编辑距离为3。现在给你两个任意字符串(不包含空格),请帮忙计算它们的最短编辑距离。输入描...原创 2019-03-24 17:05:45 · 659 阅读 · 0 评论 -
最长上升子序列 ( Longest Increasing Subsequence)
Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increas...原创 2019-03-31 12:11:11 · 199 阅读 · 0 评论 -
LeetCode|Pow(x, n)
Pow(x, n)Implement pow(x, n), which calculates x raised to the power n (xn).Example 1:Input: 2.00000, 10Output: 1024.00000Example 2:Input: 2.10000, 3Output: 9.26100Example 3:Input: 2.00000,...原创 2019-03-08 19:52:06 · 254 阅读 · 0 评论 -
希尔排序
#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <vector>using namespace std;void shell_sort(vector<int>& arr){ /* 不稳...原创 2019-03-02 23:22:40 · 100 阅读 · 0 评论 -
选择排序
选择排序#include <iostream>#include <algorithm>#include <queue>#include <stack>#include <vector>using namespace std;void selection_sort(vector<int>& arr){ ...原创 2019-03-02 15:11:31 · 119 阅读 · 0 评论 -
LeetCode|Implement Trie (Prefix Tree)
Implement Trie (Prefix Tree)Implement a trie with insert, search, and startsWith methods.Note: You may assume that all inputs are consist of lowercase letters a-z.class TrieNode {public: // Initi原创 2016-05-21 12:56:07 · 395 阅读 · 0 评论 -
双指针法题目总结
Move ZeroesGiven an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling原创 2016-04-23 17:48:12 · 704 阅读 · 0 评论 -
优先队列
堆排序 自己实现优先队列 c++ cpp原创 2015-10-20 13:16:46 · 568 阅读 · 0 评论 -
堆排序
堆排序:不稳定排序: 9 / \ 8 -----> 大根堆去掉根9 / \ / \ 5 2 1 8 / \ ...原创 2015-09-29 17:35:41 · 517 阅读 · 0 评论 -
LeetCode|Valid Parentheses
Valid ParenthesesGiven a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” ar原创 2016-04-26 08:01:18 · 354 阅读 · 0 评论 -
快速排序
目录快速排序递归版本快速排序三路快速排序非递归/迭代法快速排序稳定版本快速排序快速排序递归版本快速排序#include <iostream>#include <cstdio>#include <ctime>#include <cstdio>using namespace std;template <...原创 2015-09-29 17:34:06 · 850 阅读 · 0 评论 -
大白话解析模拟退火算法
一. 爬山算法 ( Hill Climbing ) 介绍模拟退火前,先介绍爬山算法。爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解。 爬山算法实现很简单,其主要缺点是会陷入局部最优解,而不一定能搜索到全局最优解。如图1所示:假设C点为当前解,爬山算法搜索到A点这个局部最优解就会停止搜转载 2015-06-12 00:16:11 · 762 阅读 · 0 评论 -
归并排序
目录连续结构的归并排序:递归版:迭代版本归并排序链式结构的归并排序:单链表版本连续结构的归并排序:递归版:#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#i...原创 2015-09-29 17:38:56 · 510 阅读 · 0 评论 -
基数排序
基数排序原创 2015-09-29 17:12:24 · 1585 阅读 · 1 评论 -
匈牙利算法
原文链接:http://blog.csdn.net/dark_scope/article/details/8880547匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名。匈牙利算法是基于Hall定理中充分性证明的思想,它是部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最大匹配的算法。-------等等,看得头大?那么请看下面的版转载 2015-06-11 13:08:23 · 674 阅读 · 0 评论 -
HALL定理
维基百科:https://en.wikipedia.org/wiki/Hall%27s_marriage_theoremHall 结婚定理(Hall’s MarriageTheorem or Hall's theorem)由英国数学家Philip Hall提出(The graph theoretic formulation deals witha bipartite graph. It giv原创 2015-06-18 10:18:41 · 2961 阅读 · 0 评论 -
栈的连续与链式实现
栈的实现原创 2015-09-29 16:50:18 · 581 阅读 · 0 评论 -
计算逆序对/逆序数
利用归并排序计算逆序对#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <stack>using namespace std;long long ans;i...原创 2016-04-15 23:50:37 · 1217 阅读 · 0 评论 -
LeetCode|String to Integer (atoi)
String to Integer (atoi) Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are t原创 2016-04-30 11:23:40 · 359 阅读 · 0 评论 -
链表题目总结
单链表原创 2016-04-16 00:50:15 · 908 阅读 · 0 评论 -
二叉树题目总结
Invert Binary TreeInvert a binary tree.Recursion:class Solution {public: TreeNode* invertTree(TreeNode* root) { if(root == NULL) return NULL; swap(root->left, root->right);原创 2016-04-21 23:07:40 · 1145 阅读 · 0 评论 -
二分法汇总
二分法汇总原创 2019-03-26 00:29:26 · 1195 阅读 · 0 评论