算法
Iwakura Rein
这个作者很懒,什么都没留下…
展开
-
动态规划解最长回文子串问题
问题描述给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。示例 1:输入: "babad"输出: "bab" ("aba" 也是一个有效答案)示例 2:输入: "cbbd"输出: "bb"来源:力扣(LeetCode)状态转移方程P(i,j){j>i+1 and P(i+1,j−1) and S[i]==s[j]j==i+1 and S[i]==S[j]i==jP(i,j)原创 2020-07-23 11:12:24 · 125 阅读 · 0 评论 -
满二叉树(一维数组)的所有结点的左右子树交换的C++实现
源代码#include <iostream>#include <cmath>using namespace std;template <typename T>void Reverse(T a[], int begin, int end) { for (int i = begin, j = end; i < j; i++, j--) { ...原创 2019-12-27 14:41:05 · 274 阅读 · 0 评论 -
直接插入排序、希尔排序、快速排序和归并排序的C++代码
源代码#include <iostream>using namespace std;template <typename T, int N>void InsertSort(T (&a)[N]) { for (int i = 1; i < N; i++) { if (a[i] < a[i - 1]) { ...原创 2019-12-25 13:58:55 · 241 阅读 · 0 评论 -
C++实现霍夫曼编码
#include <iostream>#include <string>#include <cstdlib>#include <vector>#include <algorithm>using namespace std;class HNode {public: int weight; string con...原创 2020-12-22 10:41:17 · 2242 阅读 · 1 评论 -
最大子段和问题:四种不同时间复杂度的算法
问题描述给定一个序列,求出其元素和最大的一个子序列。如果序列所有元素为负数,那么规定最大和为0,最大子序列为空。注意子序列里的元素在原序列中是相邻的(不然的话只要把原序列所有正数找出来就行了)。例序列:[12, 5, -1, 31, -61, 59, 26, -53, 58, 97, -93, -23, 84, -15, 6]最大子序列:[59, 26, -53, 58, 97]穷举算法...原创 2019-12-02 16:00:01 · 7093 阅读 · 0 评论