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

查看网站外链代码wordpress 还原

查看网站外链代码,wordpress 还原,xp做网站,seopeixun【问题描述】[中等] 【解答思路】 1. 动态规划 动态规划流程 第 1 步#xff1a;设计状态 dp[i] 表示字符串的前 i 个字符的最少未匹配数。 第 2 步#xff1a;状态转移方程 假设当前我们已经考虑完了前 i -1个字符了#xff0c;对于前 i 个字符对应的最少未匹配数#…【问题描述】[中等] 【解答思路】 1. 动态规划 动态规划流程 第 1 步设计状态 dp[i] 表示字符串的前 i 个字符的最少未匹配数。 第 2 步状态转移方程 假设当前我们已经考虑完了前 i -1个字符了对于前 i 个字符对应的最少未匹配数 第 i 个字符未匹配则 dp[i] dp[i1] 1即不匹配数加 1; 遍历前 i -1个字符若以其中某一个下标 j 为开头、以第 i 个字符为结尾的字符串正好在词典里则 dp[i] min(dp[ i ], dp[ j ]) 更新 dp[i]。 第 3 步考虑初始化 int[] dp new int[n1]; dp[0] 0; 第 4 步考虑输出 dp[n]; 时间复杂度O(N^3) 空间复杂度O(N) class Solution {public int respace(String[] dictionary, String sentence) {SetString dic new HashSet();for(String str: dictionary) dic.add(str);int n sentence.length();//dp[i]表示sentence前i个字符所得结果int[] dp new int[n1];for(int i1; in; i){dp[i] dp[i-1]1; //先假设当前字符作为单词不在字典中for(int j0; ji; j){if(dic.contains(sentence.substring(j,i))){dp[i] Math.min(dp[i], dp[j]);}}}return dp[n];} } 2. Trie字典树优化 复杂度分析 class Solution {public int respace(String[] dictionary, String sentence) {int n sentence.length();Trie root new Trie();for (String word: dictionary) {root.insert(word);}int[] dp new int[n 1];Arrays.fill(dp, Integer.MAX_VALUE);dp[0] 0;for (int i 1; i n; i) {dp[i] dp[i - 1] 1;Trie curPos root;for (int j i; j 1; --j) {int t sentence.charAt(j - 1) - a;if (curPos.next[t] null) {break;//单词终结标志} else if (curPos.next[t].isEnd) {dp[i] Math.min(dp[i], dp[j - 1]);}if (dp[i] 0) {break;}curPos curPos.next[t];}}return dp[n];} }class Trie {public Trie[] next;public boolean isEnd;public Trie() {next new Trie[26];isEnd false;}public void insert(String s) {Trie curPos this;for (int i s.length() - 1; i 0; --i) {int t s.charAt(i) - a;if (curPos.next[t] null) {curPos.next[t] new Trie();}curPos curPos.next[t];}//给遍历的时候的单词终结标志curPos.isEnd true;} } 3. 字符串哈希 复杂度分析 class Solution {static final long P Integer.MAX_VALUE;static final long BASE 41;public int respace(String[] dictionary, String sentence) {SetLong hashValues new HashSetLong();for (String word : dictionary) {hashValues.add(getHash(word));}int[] f new int[sentence.length() 1];Arrays.fill(f, sentence.length());f[0] 0;for (int i 1; i sentence.length(); i) {f[i] f[i - 1] 1;long hashValue 0;for (int j i; j 1; --j) {int t sentence.charAt(j - 1) - a 1;hashValue (hashValue * BASE t) % P;if (hashValues.contains(hashValue)) {f[i] Math.min(f[i], f[j - 1]);}}}return f[sentence.length()];}public long getHash(String s) {long hashValue 0;for (int i s.length() - 1; i 0; --i) {hashValue (hashValue * BASE s.charAt(i) - a 1) % P;}return hashValue;} } 【总结】 1.动态规划流程 第 1 步设计状态 第 2 步状态转移方程 第 3 步考虑初始化 第 4 步考虑输出 第 5 步考虑是否可以状态压缩 2. Rabin-Karp 字符串编码 (字符串哈希) 3.Trie class Trie {public Trie[] next;public boolean isEnd;public Trie() {next new Trie[26];isEnd false;}public void insert(String s) {Trie curPos this;for (int i s.length() - 1; i 0; --i) {int t s.charAt(i) - a;if (curPos.next[t] null) {curPos.next[t] new Trie();}curPos curPos.next[t];}curPos.isEnd true;} } 转载链接https://leetcode-cn.com/problems/re-space-lcci/solution/hui-fu-kong-ge-by-leetcode-solution/ Rabin-Karp 字符串编码 参考链接https://leetcode-cn.com/problems/longest-happy-prefix/solution/zui-chang-kuai-le-qian-zhui-by-leetcode-solution/
http://www.yutouwan.com/news/184823/

相关文章:

  • 苏州嘉盛建设工程有限公司网站公司方案策划书
  • h5 建站网站 移动端社区网站建设
  • 石家庄外贸网站推广wordpress调取列表页
  • 上海哪个网站专门做宝宝宴的建造师网
  • 网站开发连接数据库的方法北京手机网站设计电话
  • 移动网站建设哪家便宜中国住房和城乡建设部建造师网站
  • 宁阳县住房和城乡建设局网站学校电商平台的创建
  • wordpress怎么加快网站打开速度seo推广顾问
  • 网络优化和推广昆明网站关键词优化
  • 展示型网站案例光明新区网站建设
  • 天津网站优化哪家快新建免费网站
  • 做旅游的网站营销推广方案怎么写
  • 龙岩网站制作设计网络小说排行榜
  • 北京建设学院网站天津网站设计网站制作
  • 设置网站的默认页面百度网盘app下载安装官方免费版
  • 图片上传网站源码整站seo排名公司
  • 公司网站建设的系统功能需求长春网站优化seo
  • 建站平台转型怎么做便民信息网站
  • 中小企业网站的建设实践报告内江做网站多少钱
  • 如何跟进psd做网站wordpress的登录页面模板
  • 厦门专业网站免费的网页模板网站
  • 丽水微信网站建设公司营销型单页面网站
  • 织梦网站装修公司源码建一个网站流程
  • 门户网站的建设制作单页网站多少钱
  • php网站进后台从零开始学wordpress
  • 网站进入考核期要多久wordpress密码错误
  • 文化建设 设计公司网站公众号怎么开通商城
  • WordPress瀑布流图片站单位网址怎么编
  • 企业系统建设赣州做网站优化
  • 创建app与网站的区别wordpress linux伪静态