- 博客(13)
- 收藏
- 关注
原创 RGB三色排序 R...RG...GB...B
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;void solve(string &str){ int begin = 0; int current = 0; int end = str.length()-1; while(current <= end) { if(str[current].
2021-05-15 20:22:48
1291
原创 最小跳跃数
#include <iostream>#include <string.h>#include<cstdlib>#include <ctime>using namespace std;int minjump_number(int a[],int n){ int reach = 0,last = 0,count = 0,i; if (n==0 or n==1) return 0; else { .
2021-04-17 21:33:30
156
原创 【LeetCode 1014】最佳观光对 Best Sightseeing Pair
#include <iostream>#include <string.h>using namespace std;int maxScoreSightseeingPair(int a[],int n){ int i,j; int max = -999999; i = 0; for (j = 1; j < n; j++) { if (a[i]+i+a[j]-j > max) max =.
2021-04-17 20:49:16
132
原创 leetcode-1021 删除最外层的括号
题目描述有效括号字符串为空 ("")、"(" + A + “)” 或 A + B,其中 A 和 B 都是有效的括号字符串,+ 代表字符串的连接。例如,"","()","(())()" 和 “(()(()))” 都是有效的括号字符串。如果有效字符串 S 非空,且不存在将其拆分为 S = A+B 的方法,我们称其为原语(primitive),其中 A 和 B 都是非空有效括号字符串。给出一个非空有效字符串 S,考虑将其进行原语化分解,使得:S = P_1 + P_2 + … + P_k,其中 P_i
2021-04-17 20:32:32
127
原创 最大上升子序列和 和 最大下降子序列和
#include <iostream>using namespace std;void Lis_inc(int a[],int n){ int i,j; int *f = new int [n]; f[0] = a[0]; for (i = 1;i < n;i++) { f[i] = a[i]; for (j = 0;j < i ;j++) if (a[j] < a[i]) .
2021-03-12 14:51:46
239
原创 最大上升子序列和最大下降子序列O(nlgn)复杂度
#include <iostream>#include<algorithm>using namespace std;void Lis_inc(int a[],int n){ int i,j; int *f = new int [n]; for (i = 0;i < n; i++) f[i] = 0x3f3f3f3f; int len = 0; f[len] = a[0]; for (i = 1;i < n;.
2021-03-12 11:23:21
206
原创 爬山
代码#include <iostream>using namespace std;void Lis_inc_dec_max(int a[],int n){ int i,j; int *f1 = new int [n]; int *f2 = new int [n]; for (i = 0;i < n;i++) { f1[i] = 1; for (j = 0;j < i ;j++) ..
2021-03-11 20:49:48
118
原创 最长上升子序列和最长下降子序列
#include <iostream>using namespace std;void Lis_inc(int a[],int n){ int i,j; int *f = new int [n]; for (i = 0;i < n;i++) { f[i] = 1; for (j = 0;j < i ;j++) if (a[j] < a[i]) f[i] = max(f[i.
2021-03-11 20:21:58
123
原创 矩阵乘法
#include<iostream>using namespace std;const int N=7;//p为矩阵链,p[0],p[1]代表第一个矩阵的行数和列数,p[1],p[2]代表第二个矩阵的行数和列数......length为p的长度//所以如果有六个矩阵,length=7,m为存储最优结果的二维矩阵,s为存储选择最优结果路线的//二维矩阵void MatrixChainOrder(int *p,int m[N][N],int s[N][N],int length){.
2021-03-11 19:52:23
238
原创 最长公共子串
1.题目给定两个字符串A和B,长度分别为m和n,要求找出它们最长的公共子串,并返回其长度。例如: A = "HelloWorld" B = "loop"则A与B的最长公共子串为 "lo",返回的长度为2。2.代码#include <iostream>#include <string>#include <stack>using namespace std;void LCS(string s1,string s2){ int..
2021-03-11 19:46:49
226
原创 最长公共子序列
1.题目给定两个字符串,求解这两个字符串的最长公共子序列(Longest Common Sequence)。比如字符串1:BDCABA;字符串2:ABCBDAB则这两个字符串的最长公共子序列长度为4,最长公共子序列是:BCBA2.代码#include <iostream>#include <string>#include <stack>using namespace std;void LCS(string s1,string s2){
2021-03-11 19:38:47
138
原创 切分钢条
1.题目:一家公司购买长钢条,将其切割成短钢条出售,切割本身没有成本,长度为i的短钢条的价格为Pi。那给定一段长度为n的钢条和一个价格表Pi,求钢条的切割方案使得收益Rn最大。2. 动态规划代码#include <iostream>using namespace std;int p[11] = {0,1,5,8,9,10,17,17,20,24,30};int Bottom_up_cut_rod(int p[],int n){ int *r = new int.
2021-03-11 19:35:37
132
原创 最大子数组和
题目:最大子数组和1.题目描述所谓的最大子数组问题,指的是:给定一个数组A,寻找A的和最大的非空连续子数组。比如,数组 A = [-2, -3, 4, -1, -2, 1, 5, -3], 最大子数组应为[4, -1, -2, 1, 5],其和为7。2.解题思路 2.1 动态规划2.2 分治法3.代码3.1 动态规划#include <iostream>using namespace std;void Max_subarray(int A[],in...
2021-03-11 19:19:54
265
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅