Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1946 Accepted Submission(s): 596
1 #include<iostream> 2 #include<cstdio> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 const int MAX = 100005; 7 const int INF = 10000000; 8 int dp[MAX],a[MAX],b[MAX],ans,n,k; 9 int bin(int t) 10 { 11 int left=1,right=n,mid; 12 while(left<=right) 13 { 14 mid=(left+right)/2; 15 if(t>b[mid]) 16 left=mid+1; 17 else 18 right=mid-1; 19 } 20 return left; 21 } 22 23 int LIS() 24 { 25 int i,j; 26 ans=0; 27 for(i=1;i<=n;i++) 28 { 29 dp[i]=bin(a[i]); 30 if(dp[i]>ans) 31 ans=dp[i]; 32 j=i-k; 33 if(j>0 && b[dp[j]]>a[j]) 34 b[dp[j]]=a[j]; 35 } 36 return ans; 37 } 38 39 int main() 40 { 41 int t,i,j; 42 while(~scanf("%d %d",&n,&k)) 43 { 44 for(i=1;i<=n;i++) 45 { 46 scanf("%d",&a[i]); 47 b[i]=INF; 48 } 49 printf("%d\n",LIS()); 50 } 51 52 return 0; 53 }
HDU 4521 小明系列问题——小明序列 (LIS加强版)
原文:http://www.cnblogs.com/caterpillarofharvard/p/4230198.html