# Algorithm exercises---DP to solve the longest ascending subsequence (LIS)

Source: Internet
Author: User

description of the problem:

For 2,5,3,1,9,4,6,8,7, find out the number of longest ascending subsequence

Longest ascending subsequence definition:

For I<j I,J∈A[0...N] Meet A[i]<a[j]

1. Find the DP formula:
Dp[i] = Dp[j] + 1 (j<i && a[j]<a[i] && Dp[i] < dp[j]+1)

2. Implementing the Code

`void Main () {dp_lis (); Console.WriteLine (Dparr);} Static int[] arr = new Int[9]{2,5,3,1,9,4,6,8,7};static int n = 9;static int[] Dparr = new int[9];static void Dp_lis () {for (Var i= 0;i < n; i++) {Dparr[i] = 1;for (var j = 0;j < I; j + +) {if (Arr[j]<arr[i] && dparr[i] < Dparr[j] + 1) {Dparr[i]  = Dparr [J]+1;}}}`

Dparr[0...n-1], the largest element is the request.

As a connection, this example prints out all the elements in the DP array

Algorithm exercises---DP to solve the longest ascending subsequence (LIS)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.