
算法导论学习
a_Mao2016
这个作者很懒,什么都没留下…
展开
-
最基本的敌兵布阵C++实现杭电1166
#include#includeusing namespace std;#define MAXN 50000int tree[MAXN*2+1];void build(int node, int l, int r, int *s){ if(l == r) { tree[node] = s[l]; return; } else { int m = (l+r)>>原创 2017-10-18 20:42:24 · 677 阅读 · 0 评论 -
各种常见排序算法的C++实现
冒泡排序冒泡排序是大多数人学到的第一个排序,其基本思想把最小的元素像冒泡一样浮到顶端,时间复杂度为O(n^2)//BubleSort//Each iteration, the least element buble up.void BubleSort(int *P, int n){ for(int i=0;i<n;i++){ for(int j=n-1...原创 2017-10-27 11:45:16 · 441 阅读 · 0 评论 -
Trie树的C++简单实现
Trie是一种用来高效保存字符串的数据结构,是AC自动机多模匹配算法的基础#include<iostream>#include<stdio.h>#include<string>#include<string.h>using namespace std;#define maxnode 10000//Trie树中的节点数#define sigma 26//26个小写英文字幕//Trie类原创 2017-10-21 12:42:11 · 819 阅读 · 0 评论 -
基于动态规划的最长公共子序列实现(LCS)
问题描述:在生物学中,经常要通过比对DNA序列来得到两个DNA的相似度,其中一种方式是寻找两个子序列的最长公共子序列来衡量相似度。例如:1:ACGCGCGCGAC 2:ACGCTTTTTTTT 的最长公共子序列就是 3:ACGCInput:ACGCGCGCGACACGCTTTTTTTTOutput:ACGC#include#inclu原创 2017-10-11 22:52:53 · 365 阅读 · 0 评论 -
编辑距离C++实现(poj3356)
编辑距离 poj3356采用动态规划的思想,对子问题的最优解进行备份,自底向上边在递归式中直接调用备份解。#include<iostream>#include<string>using namespace std;int L[1001][1001];//备份的二维数组int a,b,c;void LED(int m, int n, string x, string y)//生成最优解的函数原创 2017-10-14 13:24:35 · 1894 阅读 · 0 评论 -
数字三角形动态规划poj1163
poj1163 数字三角形本机可以运行,提交就runtime error#includeusing namespace std;int record[105][105];int idxhelper(int k){ return k*(k-1)/2;}int dp(int N, int s[]){ for(int i=1; i<N+1;i++) {原创 2017-10-14 20:19:57 · 355 阅读 · 0 评论 -
NYOJ的矩形嵌套问题
同样是本机可以运行,但在oj上编译错误欸描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽。矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b<d或者b<c,a<d(相当于旋转X90度)。例如(1,5)可以嵌套在(6,2)内,但不能嵌套在(3,4)中。你的任务是选出尽可能多的矩形排成一行,使得除最后一个外,每一个矩形都可以嵌套在下一个矩形内。输入第一行是一个正正数原创 2017-10-14 21:51:23 · 774 阅读 · 0 评论 -
dijkastra算法实践poj2387
poj2387题目链接Dijkstra算法入门题目描述:找出图G中从点1到N得最短路径InputLine 1: Two integers: T and N Lines 2..T+1: Each line describes a trail as three space-separated integers. The first two integers are the landmarks bet原创 2017-11-04 21:25:19 · 386 阅读 · 0 评论 -
算法分析作业
#include<iostream>#include <time.h>#include<cstdlib>#include<ctime>#define random(x) (rand()%x)using namespace std;//double sort int S[1000000]; int begin; int end;vo...原创 2018-03-09 14:50:01 · 346 阅读 · 0 评论