最长递增字串
来源:互联网 发布:梦幻西游mac下载补丁 编辑:程序博客网 时间:2024/06/08 00:57
public class Zuichangdizengzichuang { public static void main(String args[]) { Integer[] a = new Integer[]{4,6,8,10,34,65,2,43,54,76,86,54,33,23,55}; MaxIncreSubSequence<Integer> mss = new MaxIncreSubSequence<Integer>(a); System.out.println(mss.getNumOfMaxIncreSubSequence()); MaxIncreCloseSubSequence<Integer> mcss = new MaxIncreCloseSubSequence<Integer>(a); System.out.println(mcss.getNumOfMaxIncreCloseSubSequence()); } //连续最长递增子串 static class MaxIncreCloseSubSequence<T extends Comparable<? super T>>{ T[] t ; public MaxIncreCloseSubSequence(T[] t) { this.t = t; } public int getNumOfMaxIncreCloseSubSequence() { int res = 0, find = 1; for(int i = 0; i < t.length; i++) { if(i + 1 < t.length && t[i].compareTo(t[i+1]) < 0) { find++; } else { res = Math.max(find, res); find = 0; } } return res; } } //最长递增字串,不一定连续。用一个数组tmp保存计算过的数据,tmp[i]表示到i+1位置时的递增字串长度 static class MaxIncreSubSequence<T extends Comparable<? super T>>{ T[] t ; public MaxIncreSubSequence(T[] t) { this.t = t; } public int getNumOfMaxIncreSubSequence() { int[] tmp = new int[t.length]; int res = 0; for(int i = 0; i < t.length ; i++) { tmp[i] = 1; for(int j = 0; j < i; j++ ) { if(t[j].compareTo(t[i]) < 0) tmp[i] = Math.max(tmp[i], tmp[j] + 1); } res = Math.max(res, tmp[i]); } return res; } }}
结果是
9
6
0 0
- 最长递增字串
- 最长递增子序列,最长递增字串
- HDOJ 1025 最长递增字串
- 【复习】最大连续子区间 最长递增字串
- 求字符串中最长连续递增子数字串
- 最大子序列,最长递增子序列,最长公共字串,最长公共子序列,字符串编辑距离
- 【面试题】给定一个仅包含字母和数字(0-9)的字符串,要求找到最长递增的数字串
- 最大连续递增数字串
- 最长公共字串
- 最长公共字串
- 最长公共字串
- 最长公共字串
- 最长公共字串
- 最长回文字串
- 获取最长字串
- 最长不重复字串
- 最长重复字串
- 最长非重复字串
- 4-11 求自定类型元素序列的中位数 (25分)
- simHash 简介以及 java 实现
- unity UI自动排列并可滑动查看
- A New Stone Game POJ 1740
- 理解 IntelliJ IDEA 的项目配置和Web部署
- 最长递增字串
- Tensorflow 回归问题
- Ubuntu14 安装rz、sz
- JavaScript push() 方法
- NYOJ
- 一个古老故事--线程和线程池的故事
- git 常用命令大全
- 相似文档查找算法之 simHash
- java.lang.ClassNotFoundException: ContextLoaderListener