
算法
银灯玉箫
这个作者很懒,什么都没留下…
展开
-
动态规划-编辑距离
求解编辑距离问题题目大意:求解两个字符串的编辑距离。将一个字符串变为另一个字符串所需要进行的最小编辑动作,这里的编辑动作包括插入、删除、字符替换。一.算法设计这是一道经典的动态规划问题,两个字符串的对齐方式很多,如果要将所有的对齐方式都考虑一遍,算法的效率将十分低下。分解子问题的办法是看两个字符串的前缀,现令E[i,j]表示字符串x与字符串y的相应前缀的编辑距离,则E[n,m]就是所求的答案...原创 2020-01-17 16:59:28 · 189 阅读 · 0 评论 -
动态规划-Subarray Sum Equals K-子数组和为K
给定一个整数数组和一个整数 k,你需要找到该数组中和为 k 的子数组。如果存在该子数组返回true,否则返回false。#include <iostream>#include <vector>using namespace std;int main() { std::cout << "Hello, World!" << std::...原创 2020-01-17 16:45:33 · 300 阅读 · 0 评论 -
动态规划-LCS最长公共子序列
LCS(S1,S2) 是求 S1[0…m] 和 S2[0…n] 的最长公共子序列的长度s1[m]==s2[n]则LCS(m,n) = 1+LCS(m-1,n-1)s1[m] != s2[n]则 LCS(m,n)=max(LCS(m-1,n), LCS(m,n-1))for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ i...原创 2020-01-17 16:41:38 · 132 阅读 · 0 评论 -
hdu1045 Fire Net (DFS+回溯)
// http://acm.hdu.edu.cn/showproblem.php?pid=1045#include <string>#include <iostream>#include <vector>#include <cstdio>#include <queue>#include <map>#include...原创 2018-08-04 17:04:39 · 157 阅读 · 0 评论 -
红黑树
Operations on red-black trees take O(logN)O(logN) time in the worst case.A red-black tree is a binary tree is a binary search tree with the following coloring properties:Every node is colored either r转载 2018-04-02 15:47:14 · 195 阅读 · 0 评论 -
贪心算法 笔记
背包相关问题。 1. 给出n 个物品,第i 个物体的重量为wiw_{i}, 选择尽量多的物体,使得总重量不超过CC. 按照物品重量从到小排序 2. 部分背包问题。有nn 个物体,第ii 个物体的重量为wiw_{i},价值为viv_{i},在总重量超过C的情况下让总价值尽量高。 按照“价值除以重量的值”排序乘船问题。 有nn 个人,第ii 个人的重量为wiw_{i},每艘船的最大载原创 2018-04-09 21:33:40 · 279 阅读 · 0 评论 -
Advanced Data Structures and Implementation
12.1 Top-Down Splay Trees An example of the top-down splaying algorithm is shown in Figure 12.4. How to insert an item into a tree?A new node is allocated(if necessary), and if the tree is empty, a o转载 2018-01-02 16:02:45 · 285 阅读 · 0 评论 -
Tree
A property of a binary tree is important is that the depth of an average binary tree is considerably smaller than N. Actually, the average depth is O(n√)O(\sqrt{n}). And for the the binary search tree,原创 2017-12-12 16:53:54 · 290 阅读 · 0 评论 -
快速幂取模算法
研究问题假设给定数值a、b、c,如何快速求解 a^b %c ?常用公式(1) (a+b)%c = ((a%c)+(b%c))%c; 如 (3+4)%2 = (3%2+4%2)%2 = (1+2)%2 = 1;(2) (a*b)%c = ((a%c)*(b%c))%c;如 (3*8)%2 = ( (3%2)*(8%2) ) %2 = (1*0) %2 = 0;(3) a^b %c = (a%c原创 2016-09-02 15:46:50 · 383 阅读 · 0 评论 -
DAG 上的动态规划(一)
DAG 模型一 嵌套矩形问题问题描述: 嵌套矩形问题。 有n个矩形,每个矩形可以用两个整数a,b描述,表示它的长和宽。矩形X(a,b)可以嵌套在矩形Y(c,d)中,当且仅当 a小于c,b小于d,或者,b小于c,a小于d。例如X(1,5)能嵌套在Y(6,2)中,但不能嵌套在(3,4)中。你的任务是选出尽量多的矩形排成一行,使得除最后一个外,每一个矩形都可以嵌套在下一个矩形内。如果有多解,矩形编号的字原创 2016-09-13 11:08:36 · 3456 阅读 · 0 评论 -
欧拉回路
问题描述:给定一个无向图,是否存在这样一条路线:从无向图任意一个结点出发,遍历图的每条边恰好一次。若存在,则称这条路线为欧拉道路(因为它是由大数学家欧拉首先提出并给出完美的解答)。解决思路: 在欧拉道路中,除起点和终点外,其他节点的进度和出度是相等的,即其他节点的度数为偶数。我们把一个节点度数为奇数的节点称为奇点。而在欧拉道路中,只可能存在0个或2个奇点,不可能存在1个奇点。奇点数为2: 奇原创 2016-09-10 17:04:36 · 618 阅读 · 0 评论 -
动态规划之0-1 背包问题
问题描述:有n种物品,每种只有一个。第i种物品的体积为Vi,重量为Wi。挑选若干物品装到一个容量为C的背包中,使得背包内物品在总体积不超过C的前提下重量尽可能大。 ps:容量对应体积 1<=n<=100, 1<=Vi<=C<=10000,1<=Wi<=10^6#include <algorithm>#include <cmath>#include <cstdio>#include原创 2016-09-09 10:36:06 · 302 阅读 · 0 评论