当前位置: 首页 > news >正文

北京网站制作人才淘宝seo具体优化方法

北京网站制作人才,淘宝seo具体优化方法,网站开发拖延交货算商业诈骗,介绍企业的ppt系列综述: 💞目的:本系列是个人整理为了秋招面试的,整理期间苛求每个知识点,平衡理解简易度与深入程度。 🥰来源:材料主要源于【CodeTopHot300】进行的,每个知识点的修正和深入主要参…

系列综述:
💞目的:本系列是个人整理为了秋招面试的,整理期间苛求每个知识点,平衡理解简易度与深入程度。
🥰来源:材料主要源于【CodeTopHot300】进行的,每个知识点的修正和深入主要参考各平台大佬的文章,其中也可能含有少量的个人实验自证,所有代码均优先参考最佳性能。
🤭结语:如果有帮到你的地方,就点个赞关注一下呗,谢谢🎈🎄🌷!!!
🌈【C++】秋招&实习面经汇总篇


文章目录

    • 基础知识
    • 回溯基础算法模板
      • 组合问题
        • 无重复元素的组合
        • 有重复元素的组合
      • 排列问题
        • 无重复元素的全排列
        • 有重复元素的全排列
    • HOT200回溯相关题目
        • 39. 组合总和
        • 40. 组合总和 II
        • 93. 复原 IP 地址
        • 131. 分割回文串
        • 1005. K 次取反后最大化的数组和
    • 参考博客


😊点此到文末惊喜↩︎

基础知识

  1. 回溯算法 = 穷举 + 剪枝
    • 穷举:从一个选择开始,一步步尝试每一个可能的选择,如果某次选择导致问题无法解决,则回溯并选择另一种可能,直到找到一个可行的解或者穷举所有可能的解。
    • 剪枝:在搜索过程中,根据问题的限制条件,减少搜索空间,提高算法效率
  2. 作用
    • 在多个选择中搜索出满足条件所有可能解
    • 一般地,组合问题和排列问题是在树形结构的叶子节点上收集结果,而子集问题就是取树上所有节点的结果。
  3. 回溯算法解决的问题一般为npc问题,难以使用常规算法进行解决
    • 组合问题:N个数里面按一定规则找出k个数的集合
      • 切割问题:一个字符串按一定规则有几种切割方式
      • 子集问题:一个N个数的集合里有多少符合条件的子集
    • 排列问题:N个数按一定规则选出M个,有几种排列方式
    • 棋盘问题:N皇后,解数独等等
  4. 所有的回溯法解决的问题都可以抽象为树形结构
    • 根节点是总数据集合,树枝节点是可选数据集合
    • 叶子节点为根节点到叶子节点的路径的选择集合
      在这里插入图片描述
// 结果集和路径集
vector<vector<type> res;
vector<type> path;
void backtracking(vecotr<type> candidates, int startIndex) {// 针对当前选择的合法性判断auto is_ok = [](const type &data)->bool{// type中数据项的合法性判断};// 递归出口:结点剪枝,生成慢if (is_ok(val)) {res.push_back(path);return;}// 延申和回撤路径时,可能涉及多个状态标记变量的改动for (int i = startIndex; i < candidates.size(); ++i) {分叉剪枝判断(性能高);// 状态延申改动path.push_back(candidates[i]);// 向下延申backtracking(剩余可选列表); // 回溯// 状态回撤改动path.pop_back();// 回撤延申}
}
// 主函数
vector<vector<int>> combine(vector<type>& candidates) {res.clear(); // 可以不写path.clear();// 可以不写backtracking(candidates, 0);return result;}

回溯基础算法模板

模板使用的初衷:将问题的输入转换成对应模板的输入格式,然后调用模板的函数(已经背诵的)进行快速的求解

组合问题

  1. 组合问题的复杂度
    • 时间复杂度: O ( C n k × k ) O(C_n^k × k) O(Cnk×k),总共有 C n k C_n^k Cnk种组合,每种组合需要 O ( k ) O(k) O(k) 的时间复杂度
    • 空间复杂度: O ( n ) O(n) O(n),递归深度为n,所以系统栈所用空间为 O ( n ) O(n) O(n)
无重复元素的组合
  1. 基本概述
    • 问题:从无重复元素的集合中选出K个元素组成组合,每个元素只能被选取一次,且选出的元素之间没有顺序之分。
    • 举例:从元素集合{1,2,3}中选择2个元素的组合为{(1,2),(1,3),(2,3)}。
      在这里插入图片描述
  2. 代码
    • 解决的问题:给定一个线性表,求该线性表中满足条件组合
    • 示例:求线性表中所有个数为target的结果。
    • 剪枝:列表中剩余元素(vec.size() - i) >= 所需需要的元素个数(target - path.size())
// 从候选集candidate中选出任意k个数组成的集合
vector<vector<int>> Backtracking(vector<int> &candidate, int k) {const int len = candidate.size();// 递归函数vector<int> path;			// 符合条件的路径vector<vector<int>> res;	// 符合条件的路径集合auto self = [&](auto &&self, int pos){// 递归出口:满足条件的路径加入结果集中if (path.size() == k) {res.push_back(path);return;}// i = start表示从之后剩余中选择for (int i = pos; i < len ; ++i) {if (i > len - (k-path.size())) continue;path.push_back(candidate[i]);	// 做出选择self(self, i+1);// key: 是i+1	// 递归path.pop_back();				// 撤销选择}};self(self, 0);return res;
}
有重复元素的组合
  1. 基本概述
    • 问题:从有重复元素的组合中选出若干元素组成组合,每个元素只能被选取一次,且选出的元素之间没有顺序之分。
    • 举例:从集合{1, 2, 2, 3}中选择2个元素的组合为{1, 2}、{1, 3}、{2, 2}、{2, 3}。
  2. 代码
    • 解决问题:给定一个线性表,求该线性表中满足条件组合,因为有重复元素,所以选择重复元素时只能使用一次,否则会出现集合中的重复
vector<vector<int>> Backtracking(vector<int> &candidate, int k) {// 排序sort(candidate.begin(), candidate.end());// 递归匿名函数vector<int> path;vector<vector<int>> res;auto self = [&](auto &&self, int pos){if (path.size() == k) {res.push_back(path);return;}for (int i = pos; i < candidate.size(); ++i) {// key: i > pos。第一次选取到重复的数,不会影响后面if (i > pos && candidate[i] == candidate[i-1])continue;path.push_back(candidate[i]);self(self, i+1);path.pop_back();}};// 递归调用self(self, 0);return res;
}

排列问题

  1. 组合问题的复杂度
    • 时间复杂度: O ( n × n ! ) O(n×n!) O(n×n!),一共 n ! n! n! 种组合,每种排列构造时间需要 O ( n ) O(n) O(n) 的时间复杂度
    • 空间复杂度: O ( n ) O(n) O(n),递归深度为n,所以系统栈所用空间为 O ( n ) O(n) O(n)
无重复元素的全排列
  1. 基本概述
    • 问题:无重复元素的排列是指在给定一组不同的元素中,按照一定的顺序排列出所有可能的组合,每个元素只出现一次
    • 举例:从集合{1, 2, 3},则可以产生以下6种无重复元素的排列:{1, 2, 3}、{1, 3, 2}、{2, 1, 3}、{2, 3, 1}、{3, 1, 2}、{3, 2, 1}。
      在这里插入图片描述
  2. 代码
    • 不需要使用pos,每一个i对应一位
    vector<vector<int>> permute(vector<int>& candidate) {const int len = candidate.size();vector<int> path;				// 回溯路径vector<vector<int>> res;		// 回溯结果集vector<bool> used(len, false);	// 使用标记auto self = [&](auto &&self){	// 回溯算法if (path.size() == len) {res.push_back(path);return ;}for (int i = 0; i < len; ++i) {// path里已经收录的元素,直接跳过if (used[i] == true) continue;// 增加选择used[i] = true;path.push_back(candidate[i]);// 进行回溯self(self);// 撤回选择used[i] = false;path.pop_back();}};// 调用self(self);return res;
    }
    
有重复元素的全排列
  1. 基本概述

    • 问题:无重复元素的排列是指在给定一组不同的元素中,按照一定的顺序排列出所有的不重复组合
    • 举例:从集合[1,1,2],则可以产生无重复的全排列: [1,1,2], [1,2,1], [2,1,1]
  2. 代码

    • 产生重复解的原因:例如[1,1,2], 无法区分[1(0), 1(1), 2] 和[1(1), 1(0), 2] 这两种情况的解
      在这里插入图片描述
    vector<vector<int>> permuteUnique(vector<int>& candidate) {const int len = candidate.size();sort(candidate.begin(), candidate.end());// 递归vector<int> path;vector<vector<int>> res;vector<bool> used(len, false);  // key:注意初始化auto self = [&](auto &&self){if (path.size() == len) {res.emplace_back(path);return ;}for (int i = 0; i < len; ++i) {// 有效的重复元素 && 前一个元素未被使用// 保证相同元素同层中只有第一个被使用if (i > 0 && candidate[i] == candidate[i-1] && used[i-1] == false) continue;if (used[i] == false) {used[i] = true;path.emplace_back(candidate[i]);self(self);used[i] = false;path.pop_back();}}};self(self);return res;
    }// 哈希表处理重复解
    vector<vector<int>> permuteUnique(vector<int>& candidate) {const int len = candidate.size();// 去重unordered_map<int, int> umap;for (auto &i : candidate) ++umap[i];// 回溯算法vector<vector<int> > res;vector<int> path;auto self = [&](auto &&self, int pos){// 递归出口if (pos == len) {res.push_back(path);return ;}for (auto &i : umap) {if (i.second == 0) continue;path.push_back(i.first);--i.second;self(self, pos+1);path.pop_back();++i.second;}};self(self, 0);return res;
    }
    

HOT200回溯相关题目

39. 组合总和
  1. 题目
    • 给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回
    • candidates 中的 同一个 数字可以 无限制重复被选取
    • 输入:candidates = [2,3,5], target = 4
    • 输出:[[2,2]]
      在这里插入图片描述
vector<vector<int>> combinationSum(vector<int>& candidates, int target) {vector<vector<int>> res;vector<int> path;auto self =  [&](auto &&self, int pos, int sum){// 结束条件if (sum > target) return ;if (sum == target) {res.push_back(path);return ;}// 路径回溯for (int i = pos; i < candidates.size(); ++i) {sum += candidates[i];path.push_back(candidates[i]);self(self, i, sum);	// key: 不用i+1表示可重复读取当前值sum -= candidates[i];path.pop_back();}};self(self, 0, 0);return res;
}
40. 组合总和 II
  1. 题目
    • 给定一个候选人编号的集合 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。
    • 输入: candidates = [2,5,2,1,2], target = 5,
    • 输出:[ [1,2,2], [5] ]
  2. 代码
    在这里插入图片描述
vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {const int len = candidates.size();sort(candidates.begin(), candidates.end());// 回溯部分vector<int> path;vector<vector<int>> res;vector<bool> used(len, false);int sum = 0;auto self = [&](auto &&self, int pos){// 结点剪枝if (sum == target) {res.emplace_back(path);return ;}for (int i = pos; i < len; ++i) {// 分叉剪枝: 性能高一些if (sum + candidates[i] > target) continue;if (i > 0 && candidates[i] == candidates[i-1] && used[i-1] == false) continue;if (used[i] == true) continue;used[i] = true;path.emplace_back(candidates[i]);sum += candidates[i];self(self, i+1);    // i+1表示每个元素不重复使用sum -= candidates[i];path.pop_back();used[i] = false;}};self(self, 0);return res;
}
93. 复原 IP 地址
  1. 题目
    • 给定一个只包含数字的字符串 s ,用以表示一个 IP 地址,返回所有可能的有效 IP 地址,这些地址可以通过在 s 中插入 ‘.’ 来形成
    • 输入:s = “25525511135”
    • 输出:[“255.255.11.135”,“255.255.111.35”]

在这里插入图片描述

vector<string> restoreIpAddresses(string s) {const int len = s.size();// 判断字符串s在左闭又闭区间[start, end]所组成的数字是否合法auto is_valid = [](const string& s, int start, int end) {cout << start <<' ' <<  end << endl;if (start > end) {return false;}if (s[start] == '0' && start != end) // 0开头的数字不合法return false;int num = 0;for (int i = start; i <= end; i++) {if (s[i] > '9' || s[i] < '0') { // 遇到非数字字符不合法return false;}num = num * 10 + (s[i] - '0');if (num > 255) { // 如果大于255了不合法return false;}}return true;
};
131. 分割回文串
  1. 131. 分割回文串
    • 获取[startIndex,i]在s中的子串s.substr(startIndex, i - startIndex + 1)
    // 判断是否为回文字符串
    bool isPalindrome(const string& s, int start, int end) {for (int i = start, j = end; i < j; i++, j--) {if (s[i] != s[j]) {return false;}}return true;
    }
    // 基本的回溯
    vector<vector<string>> result;
    vector<string> path; // 放已经回文的子串
    void backtracking (const string& s, int startIndex) {// 如果起始位置已经大于s的大小,说明已经找到了一组分割方案了if (startIndex >= s.size()) {result.push_back(path);return;}for (int i = startIndex; i < s.size(); i++) {// 剪枝与枝的延长if (isPalindrome(s, startIndex, i)) {   // 是回文子串// 获取[startIndex,i]在s中的子串string str = s.substr(startIndex, i - startIndex + 1);path.push_back(str);} else {  // 不是回文,跳过continue;}backtracking(s, i + 1); // 寻找i+1为起始位置的子串path.pop_back(); // 回溯过程,弹出本次已经填在的子串}
    }vector<vector<string>> partition(string s) {result.clear();path.clear();backtracking(s, 0);return result;
    }
    

1005. K 次取反后最大化的数组和
  1. 1005. K 次取反后最大化的数组和
    • sort的使用:第三个参数为自定义的排序队则,在头文件#include
    • accumulate的使用:第三个参数为累加的初值,在头文件include
    static bool cmp(int a, int b) {return abs(a) > abs(b);// 绝对值的从大到小进行排序
    }
    int largestSumAfterKNegations(vector<int>& A, int K) {// 将容器内的元素按照绝对值从大到小进行排序sort(A.begin(), A.end(), cmp); // 在K>0的情况下,将负值按照绝对值从大到小依次取反for (int i = 0; i < A.size(); i++) { if (A[i] < 0 && K > 0) {A[i] *= -1;K--;}}// 如果K为奇数,将最小的正数取反if (K % 2 == 1) A[A.size() - 1] *= -1; // 求和return accumulate(A.begin(),A.end(),0);// 第三个参数为累加的初值,在头文件include<numeric>
    }
    

少年,我观你骨骼清奇,颖悟绝伦,必成人中龙凤。
不如点赞·收藏·关注一波

🚩点此跳转到首行↩︎

参考博客

  1. 「代码随想录」47. 全排列 II:【彻底理解排列中的去重问题】详解
  2. codetop

文章转载自:
http://gonadotrophin.pfbx.cn
http://unbuilt.pfbx.cn
http://drudgingly.pfbx.cn
http://eent.pfbx.cn
http://ascertain.pfbx.cn
http://chichester.pfbx.cn
http://mesocarp.pfbx.cn
http://trichome.pfbx.cn
http://spiritualize.pfbx.cn
http://clearer.pfbx.cn
http://adjective.pfbx.cn
http://comex.pfbx.cn
http://mutilation.pfbx.cn
http://handwritten.pfbx.cn
http://commandant.pfbx.cn
http://auntie.pfbx.cn
http://demy.pfbx.cn
http://toxicologically.pfbx.cn
http://trinitrocresol.pfbx.cn
http://overcaution.pfbx.cn
http://flite.pfbx.cn
http://brahmaputra.pfbx.cn
http://nonreliance.pfbx.cn
http://bhakta.pfbx.cn
http://plainclothesman.pfbx.cn
http://sarcasm.pfbx.cn
http://hemolysin.pfbx.cn
http://jussive.pfbx.cn
http://sustaining.pfbx.cn
http://guitarist.pfbx.cn
http://croupous.pfbx.cn
http://odor.pfbx.cn
http://phony.pfbx.cn
http://carbamidine.pfbx.cn
http://electrostriction.pfbx.cn
http://anthropic.pfbx.cn
http://organic.pfbx.cn
http://amongst.pfbx.cn
http://unsaturated.pfbx.cn
http://incap.pfbx.cn
http://frontlash.pfbx.cn
http://backwardly.pfbx.cn
http://meeken.pfbx.cn
http://coenogenesis.pfbx.cn
http://countless.pfbx.cn
http://limaciform.pfbx.cn
http://monoplane.pfbx.cn
http://trot.pfbx.cn
http://uproariousness.pfbx.cn
http://apiculture.pfbx.cn
http://brainworker.pfbx.cn
http://visualiser.pfbx.cn
http://squaloid.pfbx.cn
http://latera.pfbx.cn
http://defeatist.pfbx.cn
http://gracefully.pfbx.cn
http://indication.pfbx.cn
http://juice.pfbx.cn
http://insure.pfbx.cn
http://copperware.pfbx.cn
http://hippomanic.pfbx.cn
http://platinic.pfbx.cn
http://aias.pfbx.cn
http://extemporarily.pfbx.cn
http://canaille.pfbx.cn
http://larvivorous.pfbx.cn
http://hungarian.pfbx.cn
http://demandable.pfbx.cn
http://concolorous.pfbx.cn
http://interruptable.pfbx.cn
http://incrassation.pfbx.cn
http://retainer.pfbx.cn
http://ctenophora.pfbx.cn
http://mythologize.pfbx.cn
http://fiddler.pfbx.cn
http://fundi.pfbx.cn
http://concise.pfbx.cn
http://office.pfbx.cn
http://meccano.pfbx.cn
http://bummalo.pfbx.cn
http://myoneural.pfbx.cn
http://demitint.pfbx.cn
http://madia.pfbx.cn
http://westmark.pfbx.cn
http://slavdom.pfbx.cn
http://technologic.pfbx.cn
http://sunbathe.pfbx.cn
http://egoboo.pfbx.cn
http://holm.pfbx.cn
http://kindling.pfbx.cn
http://idea.pfbx.cn
http://kwakiutl.pfbx.cn
http://tarred.pfbx.cn
http://hammond.pfbx.cn
http://shippable.pfbx.cn
http://napoleonize.pfbx.cn
http://slipstone.pfbx.cn
http://availablein.pfbx.cn
http://nagual.pfbx.cn
http://papuan.pfbx.cn
http://www.15wanjia.com/news/84032.html

相关文章:

  • 自己的网站怎么做实时监控电视剧百度搜索风云榜
  • WordPress主题开源网络优化大师app
  • 网站 做内容分发资格美容美发培训职业学校
  • 个人网站与企业网站区别广州白云区新闻头条最新消息今天
  • 临湘做网站seogw
  • 房天下怎样快速做网站培训平台
  • 简单的销售网站怎么做百度百科词条创建入口
  • 上海做网站企业软件培训机构
  • 什么秀网站做效果图免费测试seo
  • 筹划建设智慧海洋门户网站网站收录什么意思
  • 购物网站app制作怎么推广一个app
  • 先做网站还是先注册公司百度搜索优化软件
  • 新莱芜网自助建站seo
  • 自己做发卡网站百度服务电话6988
  • 重构网站在线制作网站免费
  • 国际健康旅行码360seo排名优化服务
  • 用友加密狗注册网站seo教学培训
  • 河南 网站备案网站建设公司
  • 杭州建设工程信息网站深圳网络推广团队
  • 寻找大连网站建设网站关键词seo优化公司
  • 37游戏官网中心重庆seowhy整站优化
  • 低价做网站优化大师在哪里
  • 书法网站模版亚马逊查关键词排名工具
  • 网站内容多 询盘微信引流的十个方法
  • 天津如何做百度的网站推广seo排名外包
  • 文安网站建设seo优化工作内容
  • 廉江网站建设短视频新媒体推广
  • 网站开发vs2013长春seo网站优化
  • 做外贸网站挣钱吗沈阳seo优化
  • 安监局网站做应急预案备案谷歌浏览器官网下载