随笔分类 -  算法

摘要:一、动态规划 动态规划算法是通过拆分问题,定义问题状态和状态之间的关系,使得问题能够以递推(或者说分治)的方式去解决 明确状态和转移两个问题 二、例题 例一:数字三角形 有一个由非负整数组成的三角形,第一行只有一个数,除了最下行之外每个数的左下方和右下方各有一个数.13 24 10 14 3 2 2 阅读全文
posted @ 2020-08-16 00:04 Joelin12 阅读(1428) 评论(0) 推荐(0)
摘要:bool erfen(int m){ int left=0,right=n-1;//此处right可以是数组得长度n,也可以是n-1 while(left<right)//此处可以写为left+1<=right { int mid=(left+right)/2;//此处为left+(right-le 阅读全文
posted @ 2020-08-10 23:31 Joelin12 阅读(149) 评论(0) 推荐(0)
摘要:此题的策略是选取可用范围最右边的点,一般来说该点辐射两边,左侧辐射,右侧辐射,所以用两个循环,第一个循环找出该点,第二个循环求出最右边的点 源代码: #include<iostream>#include<algorithm>using namespace std;#define maxn 1100i 阅读全文
posted @ 2020-05-29 20:40 Joelin12 阅读(170) 评论(0) 推荐(0)
摘要:方法:将S逆序与S正序相比较,谁小加哪个 源代码 #include<iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<vector>#include<cstdlib>#include<algorithm>using n 阅读全文
posted @ 2020-05-29 18:14 Joelin12 阅读(114) 评论(0) 推荐(0)
摘要:本题的关键是从可选择方法中选择哪一类最优化 答案是结束时间最早的一类 源代码 #include<iostream>#include<algorithm>#include<cstdio>#define maxn 100100using namespace std;struct w{ int endd, 阅读全文
posted @ 2020-05-29 13:16 Joelin12 阅读(136) 评论(0) 推荐(0)
摘要:贪心法遵从某种规则,不断贪心优化过程,此题规则就是优先选择面值大的硬币 源代码 #include<iostream>#include<cstdio>using namespace std;int main(){ int V[]={1,5,10,50,100,500}; int num=0,money 阅读全文
posted @ 2020-05-29 11:50 Joelin12 阅读(180) 评论(0) 推荐(0)
摘要:宽度优先搜索运用了队列(queue)在unility头文件中 源代码 #include<iostream>#include<cstdio>#include<queue>#include<algorithm>#include<utility>using namespace std;typedef pa 阅读全文
posted @ 2020-05-29 11:27 Joelin12 阅读(261) 评论(0) 推荐(0)
摘要:#include<iostream>#include<cstdio>#include<cstdlib>#define maxn 100char ch[maxn][maxn];using namespace std;int length,width;void dfs(int x,int y){ ch[ 阅读全文
posted @ 2020-05-28 11:54 Joelin12 阅读(117) 评论(0) 推荐(0)
摘要:#include<iostream>#include<stack>#define maxn 30using namespace std;stack<int>st;int n,k,a[maxn];bool dfs(int i,int sum){ if(i==k) return sum==k;//加到最 阅读全文
posted @ 2020-05-28 10:47 Joelin12 阅读(104) 评论(0) 推荐(0)
摘要:01-复杂度2 Maximum Subsequence Sum (25分) Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to be { N​i​​, 阅读全文
posted @ 2020-05-08 09:36 Joelin12 阅读(147) 评论(0) 推荐(0)
摘要:题目: 最大连续子数列和一道很经典的算法问题,给定一个数列,其中可能有正数也可能有负数,我们的任务是找出其中连续的一个子数列(不允许空序列),使它们的和尽可能大。我们一起用多种方式,逐步优化解决这个问题。 为了更清晰的理解问题,首先我们先看一组数据:8-2 6 -1 5 4 -7 2 3 输出 14 阅读全文
posted @ 2020-05-07 23:26 Joelin12 阅读(268) 评论(0) 推荐(0)