Write a method named maxSubsequenceK
that finds and returns the maximum possible sum of any increasing subsequence of values of length k in a given array, using dynamic programming.
Your method accepts two parameters: an array of integers, and an integer target K.
For example, if the array stores {8, 5, 9, 10, 5, 6, 21, 8}
and k is 3
, the value returned should be 40
because it is the sum of the 3-element subsequence {9, 10, 21}
.
The key constraint of this problem is that you must solve it using a bottom-up dynamic programming approach.
Do not use recursion.
You are allowed to construct any data structures (array, list, set, map, etc.) necessary to store the data for your dynamic programming algorithm.
You may assume that no value in the array is negative.