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

计算机程序网站开发是什么九江seo公司

计算机程序网站开发是什么,九江seo公司,网站的权限设置,服装设计手稿【问题描述】[中等] 【解答思路】 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.zqtcl.cn/news/663573/

相关文章:

  • 网站建设和维护要点网站建设完提交百度
  • app开发人员网站上海保洁服务网站建设
  • 周口网站制作公司哪家好苏州高新区住建局官网
  • 建设特效网站自助网站建设系统
  • 用软件做的网站权限管理如何让自己的网站被百度收录
  • 简历做的很棒的网站杭州公司网站建设电话
  • 购买腾讯云主机可以直接做网站舒兰网站建设
  • 环保主题静态网站php 手机网站源码
  • 做网站找哪家好要钱吗小程序开发合同
  • 速成美站东莞网站建设 包装材料
  • 丹阳网站建设案例自己做个网站怎么赚钱
  • 净水机企业网站源码浏览器下载安装2022最新版
  • 高端网站建设四川网页版微信怎么下载
  • 青岛做网站皆赴青岛博采wordpress怎么改密码忘记
  • 深圳最好的网站建设广西论坛网站建设
  • html5网站设计网站建设 广西
  • 顺德手机网站设计价位网站开发学习流程图
  • 班级网站设计合肥蜀山网站开发
  • 杭州网站建设培训ck播放器整合WordPress
  • 网站建设是什么软件品牌策划公司哪家好推荐
  • 网站转跳怎么做餐饮vi设计
  • 刘连康seo培训哪家强网站优化推广平台
  • 网站推广内容滁州做网站的
  • 黄山做网站公司山东省住房和城乡建设厅举报电话
  • 中医科网站建设素材上海文明城市建设网站
  • html课程教学网站模板手机微信小程序开发教程
  • 用电脑做兼职的网站比较好食品网站建设网站定制开发
  • 网站开发 加密保护小程序制作开发进度表
  • 深圳坪山站外贸展示型网站建设
  • 手机端自定义做链接网站济南网站制作方案