HDU4521: Xiao Ming series problems-Xiao Ming series (LIS enhanced version)

Source: Internet
Author: User

Problem Description
We all know that James prefers to study sequence-related problems, but that's why James has almost gone through various sequence problems. Poor James struggled to find new sequence problems on major websites, but finding them was a sequence he had already studied. James figured that since he could not find it, I 'd like to invent a new sequence problem by myself! James finally came up with a new sequence problem. He was ecstatic because he had come up with the new sequence problem and named it "James sequence ".

When talking about James's sequence, he defined it as follows:
① Define S as An ordered sequence. S = {A1, A2, A3,..., An}, and n are the number of elements;
② Define Sub as a subsequence taken out in S. Sub = {Ai1, Ai2, Ai3,..., Aim}, and m are the number of elements;
③ Where Sub satisfies Ai1 <Ai2 <Ai3 <... <Aij-1 <Aij + 1 <... <Aim;
④ At the same time Sub satisfies for any connected two Aij-1 and Aij have ij-ij-1> d (1 <j <= m, d is the given integer );
⑤ Obviously, there will be many Sub sequences that meet such requirements, and in the obtained Sub sequences, the Sub-sequence with the largest number of elements is called the "Xiao Ming sequence ).
Example: sequence S = {,}, where d = 1;
The m value of the "Xiao Ming sequence" is 2. That is, Sub = {2, 3}, {2, 4}, or {1, 4} are all "Xiao Ming sequences ".

When James invented the "Xiao Ming sequence", he was so excited that his mind was so messy that he wanted to ask you to help him calculate the given S sequence and integer d, how many elements are required in the "Xiao Ming sequence?

 


Input
Multiple groups of input data, processing to the end of the file;
The first two positive integers n and d are input. (1 <= n <= 10 ^ 5, 0 <= d <= 10 ^ 5)
The second input behavior is n integers A1, A2, A3,..., An, representing n elements of the S sequence. (0 <= Ai <= 10 ^ 5)
 


Output
Output the number of elements in the "Xiao Ming sequence" for each group of data, and output a row of test data for each group.
 


Sample Input
2 0
1 2
5 1
3 4 5 1 2
5 2
3 4 5 1 2


Sample Output
2
2
1

 

It is still the length of LIS, but the difference between subscripts must be within the range required by the question.

Train of Thought: Pay attention to marking. For details, see the code.

 

# Include <stdio. h> # include <string. h ># include <algorithm> using namespace std; int ans, a [100005], dp [100005], c [100005], n, k; // The a array stores the sequence // The longest incremental sub-sequence length of the dp record at the I point // The c array indicates the marker for each query. The record path is int bin (int t) {int l = 1, r = n; while (l <= r) {int mid = (l + r)/2; if (t> c [mid]) l = mid + 1; else r = mid-1;} return l;} int LIS () {int I, j; ans = 0; for (I = 1; I <= n; I ++) {dp [I] = bin (a [I]); if (dp [I]> ans) // update the longest length ans = dp [I]; j = I-k ; // Because K if (j> 0 & c [dp [j]> a [j]) must be separated. // search Mark c [dp [j] = a [j];} return ans;} int main () {int t, I; while (~ Scanf ("% d", & n, & k) {for (I = 1; I <= n; I ++) {scanf ("% d ", & a [I]); c [I] = 10000000;} printf ("% d \ n", LIS ();} return 0 ;}

 

Related Article

Contact Us

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.