随笔分类 -  趣学算法

摘要:转载至:https://www.cnblogs.com/fnlingnzb learner/p/9374732.html 一、算法概述 0.1 算法分类 十种常见排序算法可以分为两大类: 非线性时间比较类排序:通过比较来决定元素间的相对次序,由于其时间复杂度不能突破O(nlogn),因此称为非线性时 阅读全文
posted @ 2019-09-08 18:18 xjyxp01 阅读(381) 评论(0) 推荐(0)
摘要:<! flowchart 箭头图标 勿删 题目描述 给定一个数组 array[1, 4, 5, 9, 8, 3, 6],在这个数字中有多个子数组,子数组和最大的应该是:[9, 8, 3],输出20,再比如数组为[1, 2, 3, 10, 4, 7, 2, 5],和最大的子数组为[3, 10, 4, 阅读全文
posted @ 2019-09-08 16:23 xjyxp01 阅读(389) 评论(0) 推荐(0)
摘要:                    查找     插入      删除 数组       &nb 阅读全文
posted @ 2019-09-08 12:35 xjyxp01 阅读(488) 评论(0) 推荐(0)
摘要:各种排序算法总结和比较        排序算法可以说是一项基本功,解决实际问题中经常遇到,针对实际数据的特点选择合适的排序算法可以使程序获得更高的效率,有时候排序的稳定性还是实际问题中必须考虑的,这篇博客对常见的排序算法进行整理,包括:插入排序、选择排序、冒泡 阅读全文
posted @ 2019-09-08 11:09 xjyxp01 阅读(371) 评论(0) 推荐(0)
摘要:专题6 动态规划 1、动态规划基础知识 什么情况下可能是动态规划?满足下面三个条件之一:1. Maximum/Minimum 最大最小,最长,最短;写程序一般有max/min。2. Yes/No 是否可行;写程序一般有||。3. Count( ) 数方案的个数,比如有多少条路径这种。初始化0个的情况 阅读全文
posted @ 2019-09-05 10:27 xjyxp01 阅读(521) 评论(0) 推荐(0)
摘要:![](https://img2018.cnblogs.com/blog/1715840/201909/1715840-20190903180644787-896976480.png) ![](https://img2018.cnblogs.com/blog/1715840/201909/1715840-20190903180721553-1790469083.png) 阅读全文
posted @ 2019-09-03 18:08 xjyxp01 阅读(157) 评论(0) 推荐(0)
摘要:一、问题描述:有n 个物品,它们有各自的重量和价值,现有给定容量的背包,如何让背包里装入的物品具有最大的价值总和? 二、总体思路:根据动态规划解题步骤(问题抽象化、建立模型、寻找约束条件、判断是否满足最优性原理、找大问题与小问题的递推关系式、填表、寻找解组成)找出01背包问题的最优解以及解组成,然后 阅读全文
posted @ 2019-08-12 11:39 xjyxp01 阅读(262) 评论(0) 推荐(0)
摘要:2019独角兽企业重金招聘Python工程师标准>>> 背包问题是算法中的经典问题,可以用许多种方法来求解。本处详细阐述一下基于暴力搜索的背包求解。 假设有n个物体,价值和重量分别用vi和wi来表示,用暴力搜索,我们将最终的解用一个向量来表示,因此所有的解空间可以用00...00到 阅读全文
posted @ 2019-08-12 11:37 xjyxp01 阅读(760) 评论(0) 推荐(0)
摘要://program 5-3 #include #include #define MX 50 using namespace std; int x[MX]; //解分量 int map[MX][MX]; //图的邻接矩阵 int sum=0; //记录解的个数 int n,m,edge; //节点数和颜色数 //创建邻接矩阵 void CreatMap() { ... 阅读全文
posted @ 2019-08-10 18:23 xjyxp01 阅读(881) 评论(0) 推荐(0)
摘要://program 2-6 #include <iostream> using namespace std; const int INF = 0x3fffffff; const int N = 100; bool s[N]; int closest[N]; int lowcost[N]; void Prim(int n, int u0, int c[N][N]) { //顶点个数n、开始顶点u0、 阅读全文
posted @ 2019-08-10 18:15 xjyxp01 阅读(922) 评论(0) 推荐(0)
摘要://program 2-4 #include #include #include using namespace std; const int N=100; // 城市的个数可修改 const int INF=1e7; // 无穷大10000000 int map[N][N],dist[N],p[N],n,m;//n城市的个数,m为城市间路线的条数 bool flag[N]; //如果s[i]... 阅读全文
posted @ 2019-08-10 11:00 xjyxp01 阅读(506) 评论(0) 推荐(0)
摘要://program 3-3 #include using namespace std; int Partition(int r[],int low,int high)//划分函数 { int i=low,j=high,pivot=r[low];//基准元素 while(ipivot) j--;//向左扫描 if(ipivot) j--;//向左扫描 ... 阅读全文
posted @ 2019-08-07 16:08 xjyxp01 阅读(422) 评论(0) 推荐(0)
摘要://program 3-2 #include #include using namespace std; void Merge(int A[], int low, int mid, int high) { int *B=new int[high-low+1];//申请一个辅助数组 int i=low, j=mid+1, k=0; while(i>n; cout... 阅读全文
posted @ 2019-08-07 14:27 xjyxp01 阅读(179) 评论(0) 推荐(0)
摘要://program 5-4 #include #include //求绝对值函数需要引入该头文件 #define M 105 using namespace std; int n;//n表示n个皇后 int x[M]; //x[i]表示第i个皇后放置在第i行第x[i]列 long long countn; //countn表示n皇后问题可行解的个数 bool Place(int... 阅读全文
posted @ 2019-08-07 12:15 xjyxp01 阅读(134) 评论(0) 推荐(0)
摘要://program 2-3 #include #include #include using namespace std; struct Meet { int beg; //会议的开始时间 int end; //会议的结束时间 int num; //记录会议的编号 }meet[1000]; //会议的最大个数为1000 class setMeet{... 阅读全文
posted @ 2019-07-11 17:43 xjyxp01 阅读(644) 评论(0) 推荐(1)
摘要:最长公共子序列求解:递归与动态规划方法 在做OJ题目的时候,经常会用到字符串的处理。例如,比较二个字符串相似度。这篇文章介绍一下求两个字符串的最长公共子序列。 一个字符串的子序列,是指从该字符串中去掉任意多个字符后剩下的字符在不改变顺序的情况下组成的新字符串。 最长公共子序列,是指多个字符串可具有的 阅读全文
posted @ 2019-07-06 17:41 xjyxp01 阅读(1069) 评论(0) 推荐(1)
摘要://program 3-1 #include #include #include using namespace std; const int M=10000; int x,n,i; int s[M]; int BinarySearch(int n,int s[],int x) { int low=0,high=n-1; //low指向有序数组的第一个元素,high指向有序数组的最后一... 阅读全文
posted @ 2019-07-05 22:11 xjyxp01 阅读(367) 评论(0) 推荐(0)
摘要:#include #include using namespace std; const int M=1000005; struct three{ double w;//每个宝物的重量 double v;//每个宝物的价值 double p;;//性价比 }s[M]; bool cmp(three a, three b) { return a.p>b.p;... 阅读全文
posted @ 2019-07-05 21:16 xjyxp01 阅读(183) 评论(0) 推荐(0)
摘要://program 2-1 #include #include const int N=1000005; using namespace std; double w[N]; //古董的重量数组 int main() { double c; int n; cin>>c>>n; for(int i=0; i>w[i]; //输入每个物品重量 } ... 阅读全文
posted @ 2019-07-05 16:14 xjyxp01 阅读(317) 评论(0) 推荐(0)