摘要: #include<stdio.h> #include<stdlib.h> #define maxn 110000 typedef struct Node* LNode; struct Node { LNode next; int data; }; //初始化//带有头节点的链表 LNode Crea 阅读全文
posted @ 2021-03-28 11:08 Joelin12 阅读(64) 评论(0) 推荐(0)
摘要: #include<stdio.h> #define maxn 110000 struct Node { int Data[maxn]; int last; }; typedef struct Node* LNode; //初始化 LNode Creat() { LNode lis; lis=(LNo 阅读全文
posted @ 2021-03-28 10:24 Joelin12 阅读(52) 评论(0) 推荐(0)
摘要: //素数全为6n+1或是6n-1 bool judge(ll n) { if(n<4) { if(n<=1) return false; else return true; } if(n%6!=1&&n%6!=5) return false; int sq=(int)sqrt(n); for(int 阅读全文
posted @ 2021-03-27 20:48 Joelin12 阅读(95) 评论(0) 推荐(0)
摘要: 实例1.1 最大子列和问题 (20 分) 给定K个整数组成的序列{ N​1​​, N​2​​, ..., N​K​​ },“连续子列”被定义为{ N​i​​, N​i+1​​, ..., N​j​​ },其中 1。“最大子列和”则被定义为所有连续子列元素的和中最大者。例如给定序列{ -2, 11, 阅读全文
posted @ 2021-03-27 20:04 Joelin12 阅读(128) 评论(0) 推荐(0)
摘要: 1.递归实现 #include<iostream> #include<algorithm> #include<cstdio> #define ll long long using namespace std; ll x,n; ll pow(ll x,ll n) { if(n==0) return 1 阅读全文
posted @ 2021-03-27 20:02 Joelin12 阅读(313) 评论(0) 推荐(0)
摘要: 通用 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #define maxn 1100 using namespace std; //dp[i][j] 表示从第i个 阅读全文
posted @ 2021-02-15 18:17 Joelin12 阅读(34) 评论(0) 推荐(0)
摘要: 一、01背包 现在有一个背包(容器),它的体积(容量)为V,现在有N种物品(每个物品只有一个),每个物品的价值v[i]和占用空间w[i]都会由输入给出,现在问这个背包最多能携带总价值多少的物品? 输入 4 5 3 2 4 2 2 1 3 2 输出 7 解析:此题可以用dp来做。因为每个物品都有取与不 阅读全文
posted @ 2020-08-17 22:43 Joelin12 阅读(103) 评论(0) 推荐(0)
摘要: 一、动态规划 动态规划算法是通过拆分问题,定义问题状态和状态之间的关系,使得问题能够以递推(或者说分治)的方式去解决 明确状态和转移两个问题 二、例题 例一:数字三角形 有一个由非负整数组成的三角形,第一行只有一个数,除了最下行之外每个数的左下方和右下方各有一个数.13 24 10 14 3 2 2 阅读全文
posted @ 2020-08-16 00:04 Joelin12 阅读(1424) 评论(0) 推荐(0)
摘要: 摘自于:https://www.cnblogs.com/Cnxz/p/12631021.html 二维数组的题目,N小于20的,适用DFS。而一般 N<= 200,N<=1000这种,一定不可能用DFS去做。而且并不只是整个题目不能用DFS,其中的每一步也不能使用DFS。 BFS的基本步骤 1.将初 阅读全文
posted @ 2020-08-14 10:41 Joelin12 阅读(137) 评论(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 阅读(145) 评论(0) 推荐(0)