Dynamic programming - 最长单调递增子串问题
来源:互联网 发布:万达电商 大数据百家 编辑:程序博客网 时间:2024/06/09 13:48
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace LPS{ class Program { static void Main(string[] args) { int[] pre = { 9, 2, 3, 4, 5, 6 }; int[,] rec = new int[pre.Length, pre.Length]; Lps lps = new Lps(rec, pre.Length, pre); lps.Lps_initial(); lps.Lps_length(); rec = lps.Record; int [] res = res = lps.generate (); for (int i = 0; i < pre.Length; i++) { for (int j = 0; j < pre.Length; j++) { Console.Write("{0} ", rec[i, j]); } Console.Write("\n"); } for (int i = res[0]; i <= res[1];i++ ) Console.Write("{0} ",pre[i]); Console.ReadKey(); } } class Lps { public Lps(int [,] record,int x,int [] origin) { Record = record; Length = x; OriginSeq = origin; } public int[,] Record { get; set; } public int Length { set; get; } public int[] OriginSeq { get; set; } public void Lps_initial() { for (int i = 0; i < Length; i++) { for (int j = 0; j < Length; j++) { if (i == j) Record[i, j] = 1; else Record[i, j] = 0; } } } public void Lps_length() { for (int l = 2; l <= Length; l++) { for (int i = 0; i < Length - l + 1; i++) { int j = i + l - 1; if (Record[i, j - 1] == 0) Record[i, j] = 0; else if (OriginSeq[j - 1] < OriginSeq[j]) Record[i, j] = Record[i, j - 1] + 1; else Record[i, j] = 0; } } } public int[] generate() { int temp=0; int [] rec = {0,0}; for (int i = 0; i < Length; i++) { for (int j = 0; j < Length; j++) { if (Record[i, j] > temp) { temp = Record[i, j]; rec[0] = i; rec[1] = j; } } } return rec; } }}
0 0
- Dynamic programming - 最长单调递增子串问题
- 最长单调递增子序列问题
- 最长单调递增子序列问题
- 最长单调递增子序列问题
- 最长单调递增子序列-LIS问题
- 最长单调递增子序列问题
- 动态规划 (Dynamic Programming) 之 最长递增子序
- Dynamic programming - 最长回文子序列问题
- 最长单调递增子序列
- 最长单调递增子序列
- 最长单调递增子序列
- 最长单调递增子序列
- 最长单调递增子序列
- 最长单调递增子序列
- 最长单调递增子序列
- 单调递增最长子序列
- 单调递增最长子序列
- 最长单调递增子序列
- leetcode 120. Triangle
- Vector 真的线程安全吗?
- IMG标签外增加A标签后,A标签高度增加解决方案
- 二叉树的先序,中序,层次遍历,递归与非递归实现
- 1070. Mooncake (25)
- Dynamic programming - 最长单调递增子串问题
- 802.11ax前瞻4:802.11ax与HiperLan
- 关于进程
- 阻塞非阻塞与同步异步的区别
- Leetcode 486 python 解题报告
- 从0开始学习 GitHub 系列之「03.Git 速成」----转载自stormzhang 原创文章
- 手把手玩转gitHub
- C语言 · 数组查找及替换
- ScrollView的使用详细