2020年3月9日

最长上升子序列 leetcode 300

摘要: dp解法 int lengthOfLIS(vector<int>& nums) { //dp解法O(n^2) int len=nums.size(); if(len==0) return 0; vector<int> dp(len,1); int maxlen=1; for(int i=1;i<le 阅读全文

posted @ 2020-03-09 18:37 QingFengDaHui 阅读(212) 评论(0) 推荐(0) 编辑

最长回文子序列 leetcode 516

摘要: class Solution { public: int longestPalindromeSubseq(string s) { int len=s.size(); if(len==0) return 0; vector<vector<int>> dp(len,vector<int>(len,1)) 阅读全文

posted @ 2020-03-09 18:33 QingFengDaHui 阅读(125) 评论(0) 推荐(0) 编辑

leetcode 5 最长回文子串(马拉车算法)

摘要: 添加‘#’的原因是让偶数回文串也可以有中心点,添加‘!’和’?’的原因是防止len数组越界 其中len[i]表示以i为中心时,从i到以i为中心的回文串的最右边的长度 mx表示循环到此时之前所有的回文串的右边界的最大值,p表示该回文串的中心 class Solution { public: strin 阅读全文

posted @ 2020-03-09 18:30 QingFengDaHui 阅读(184) 评论(0) 推荐(0) 编辑

leetcode 28(简单kmp)

摘要: void GetNext(string &needle,int next[]) { next[0]=-1; int k=-1; int len=needle.size(); for(int i=1;i<len;i++) { while(k!=-1&&needle[k+1]!=needle[i]) k 阅读全文

posted @ 2020-03-09 18:24 QingFengDaHui 阅读(217) 评论(0) 推荐(0) 编辑

区间动态规划 scu2117 加分二叉树

摘要: 题目链接:https://vjudge.net/problem/SCU-2117 #include <iostream> #include<vector> #include<algorithm> #include<string> #include<map> using namespace std; 阅读全文

posted @ 2020-03-09 16:15 QingFengDaHui 阅读(155) 评论(0) 推荐(0) 编辑

导航