ITPub博客

首页 > 应用开发 > IT综合 > 最长非递减子串问题

最长非递减子串问题

原创 IT综合 作者:wxwahu 时间:2015-06-27 11:01:15 0 删除 编辑
package com.iflytek.dp;


public class LongestNonDecrease  {
private int[] s;
private int size;
private int[][] dp;
private LongestNonDecrease(int[] s){
this.s = s;
this.size = this.s.length;
this.dp = new int[this.size][];
for(int i = 0; i < this.size; i++){
this.dp[i] = new int[this.size];
}
}

public void fun() {
for(int i = 0; i < this.size; i++){
this.dp[i][i] = 1;
}

for (int i = 1; i < this.size; i++) {
for (int j = i - 1; j >= 0; j--) {
if (s[i] >= s[j]) {
//this.deepCopy(i, j);
this.deepCopy(this.dp[i], this.dp[j], j);
break;
}
}
}
}

public void deepCopy(int A[], int B[], int j){
for(int i = 0; i <= j; i++){
A[i] = B[i];
}
}
public void deepCopy(int i, int j){
for(int t = 0; t <= j; t++){
this.dp[i][t] = this.dp[j][t];
}
}

public static void main(String[] args) {
int arr[] = {13, 7, 9, 16, 38, 24, 37, 18};
LongestNonDecrease lnd = new LongestNonDecrease(arr);
lnd.fun();
System.out.println(lnd.dp);
}


}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29653519/viewspace-1713918/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 三角数塔问题
请登录后发表评论 登录
全部评论

注册时间:2014-05-11

  • 博文量
    5
  • 访问量
    4376