#K58107. Strictly Increasing Subsequence
Strictly Increasing Subsequence
Strictly Increasing Subsequence
You are given an array representing the number of flowers in each bed. Your task is to determine whether there exists a strictly increasing subsequence of length \( k \) among these flower beds. A strictly increasing subsequence is defined as a sequence of indices \( i_1, i_2, \ldots, i_k \) such that \( 1 \leq i_1 < i_2 < \cdots < i_k \leq n \) and the corresponding values satisfy \( a_{i_1} < a_{i_2} < \cdots < a_{i_k} \).
If such a subsequence exists, print yes
; otherwise, print no
.
Note: Use the dynamic programming approach where you maintain an array \( dp \) such that \( dp[i] \) is the length of the longest strictly increasing subsequence ending at index \( i \). The recurrence relation is given by:
[ dp[i] = \max_{0 \leq j < i \text{ and } a[j] < a[i]}{dp[j]} + 1 ]
inputFormat
The input is read from stdin and consists of three lines:
- An integer \( n \) representing the number of flower beds.
- \( n \) space-separated integers representing the number of flowers in each bed.
- An integer \( k \) representing the desired length of the strictly increasing subsequence.
outputFormat
The output is written to stdout and should be a single line containing either yes
or no
depending on whether a strictly increasing subsequence of length \( k \) exists in the given array.
6
1 2 1 2 3 4
3
yes