Dynamic Programming Problem Analysis

Dynamic Programming usually applies to 1-dimensional problem and looking for max or min problem.

Similar Problems:

  1. Longest Ascending SubArray
  2. Longest Ascending SubSequence
  3. Cutting rope
  4. Array Hopper
  5. Word Break

Problems Description:

Longest Ascending SubArray

Given an unsorted array, find the length of the longest subarray in which the numbers are in ascending order.

Assumptions

The given array is not null

Examples
{7, 2, 3, 1, 5, 8, 9, 6}, longest ascending subarray is {1, 5, 8, 9}, length is 4.
{1, 2, 3, 3, 4, 4, 5}, longest ascending subarray is {1, 2, 3}, length is 3.

Problem Analysis(Induction Rule):
dp[i] = 1: array[i] <= array[i - 1]
dp[i] = dp[i - 1] + 1: array[i] > array[i - 1]

Longest Ascending Subsequence

Given an array A[0]...A[n-1] of integers, find out the length of the longest ascending subsequence.

Assumptions

A is not null
Examples
Input: A = {5, 2, 6, 3, 4, 7, 5}
Output: 4
Because [2, 3, 4, 5] is the longest ascending subsequence.

Problem Analysis(Induction Rule):
dp[i] represents the longest ascending subsequence ending at index i

你可能感兴趣的:(java)