Xiao Ming Series Problems--Xiao Ming's sequence
Time limit:3000/1000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 1946 Accepted Submission (s): 596
Problem Description We all know that Xiao Ming likes to study the problems related to the sequence, but also because of this, xiaoming almost has been playing all kinds of sequence problems. Poor Xiaoming was struggling to find new sequence problems on various websites, but finding them was a sequence that he had already studied. Xiao Ming thought that since can not find, then he invented a new sequence problem it! Xiao Ming think, think, finally came up with a new sequence problem, he was ecstatic, because he thought out, so his new sequence problem named "Xiaoming sequence."
To mention the sequence of xiaoming, the definition he gives is this:
① first defines S as an ordered sequence, s={A1, A2, A3, ..., an},n is the number of elements;
② then defines a sub sequence to be taken out of S, sub={Ai1, Ai2, Ai3, ..., Aim},m is the number of elements;
③ where sub satisfies Ai1 < Ai2 < Ai3 < ... < Aij-1 < Aij < 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 for a given integer);
⑤ obviously satisfies such sub-subsequence there are many, and in these sub-sequence sub-sequences, the number of elements is called "xiaoming sequence" (that is, m the largest sub-subsequence).
For example: Sequence s={2,1,3,4}, where d=1;
Can get "xiaoming sequence" of the m=2. That is, sub={2,3} or {2,4} or {1,4} are all "xiaoming sequences".
When Xiao Ming invented the "xiaoming sequence" that moment, the emotion is very excited, so that the mind is messy, so he wants to ask you to help him to calculate in the given S-sequence and the whole number D, how many of the elements in the "xiaoming sequence" need?
Input data multiple sets, processing to the end of the file;
The first behavior of the input two positive integers n and D; (1<=n<=10^5, 0<=d<=10^5)
The second behavior of the input n integers A1, A2, A3, ..., an, represents n elements of the s sequence. (0<=ai<=10^5)
Output Please print out the number of elements in the "xiaoming sequence" for each set of data, one row for each test data output.
Sample Input2 01 25 13 4 5 1 25 23 4 5 1 2
Sample Output221
1#include <iostream>2#include <cstdio>3#include <string.h>4#include <algorithm>5 using namespacestd;6 Const intMAX =100005;7 Const intINF =10000000;8 intdp[max],a[max],b[max],ans,n,k;9 intBinintt)Ten { One intleft=1, right=N,mid; A while(left<=Right ) - { -Mid= (left+right)/2; the if(t>B[mid]) -Left=mid+1; - Else -right=mid-1; + } - returnLeft ; + } A at intLIS () - { - inti,j; -ans=0; - for(i=1; i<=n;i++) - { indp[i]=bin (a[i]); - if(dp[i]>ans) toans=Dp[i]; +j=i-K; - if(j>0&& b[dp[j]]>A[j]) theb[dp[j]]=A[j]; * } $ returnans;Panax Notoginseng } - the intMain () + { A intt,i,j; the while(~SCANF ("%d%d",&n,&k)) + { - for(i=1; i<=n;i++) $ { $scanf"%d",&a[i]); -b[i]=INF; - } theprintf"%d\n", LIS ()); - }Wuyi the return 0; -}
HDU 4521 Xiao Ming series Problem--Xiao Ming sequence (Lis Enhanced Edition)