- 博客(4)
- 收藏
- 关注
原创 最长公共子序列 递归+迭代 C++
给定两个序列X={x1,x2,…,xm}和Y={y1,y2,…,yn},求最长公共子序列。要求:用递归和迭代两种方法写代码。递归:#include <bits/stdc++.h>using namespace std;string a, b;int p[100][100];int LCS(int n, int m){ if (n == -1 || m == -1) return 0; if (a[n] == b[m]) return LC
2022-05-01 15:28:47 598
原创 改写二分搜索算法C++
改写二分搜索算法,使得当搜索元素x不在数组中时,返回小于x的最大元素位置i和大于x的元素位置j。当搜索元素在数组中时,i和j相同,均为x在数组中的位置。//二分查找#include <bits/stdc++.h>using namespace std;int search(vector <int> a,int n,int m){ int i = 0; int j = 0; int detection = -1; //...
2022-04-24 19:17:41 1567
原创 分治法求序列的最大值和最小值C++
给定序列,使用分治法求出序列中的最大值,最小值,并输出比较次数(不要用排序方法)//求解序列中的最大值和最小值#include <bits/stdc++.h>using namespace std;#define max(x,y) x>y?x:y#define min(x,y) x<y?x:yvoid solve(vector <int> a, int low, int high, int &Max,int &Min,int &b
2022-04-24 19:05:15 3330
原创 第13届蓝桥杯I题李白打酒加强版(C++,dfs)
#include<bits/stdc++.h>using namespace std;char s[1000];long long int ans;void dfs(int a,int b,int j,int sum,int x){//a-店 b-花 j-酒 sum-步数 x-店花总数 if(!j&&s[x-1]=='b'&&!a&&!b){ //最后一次遇到花店,并且没有酒了 ans++;re...
2022-04-14 17:04:54 736 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人