1、http://acm.hdu.edu.cn/showproblem.php?pid=1257
2、题目大意:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11161 Accepted Submission(s): 4400
8 389 207 155 300 299 170 158 65
2
2、题目类似于hdu 1677
此题思想一样,不过比1677要简单,
3、代码:
#include<stdio.h> #include<string.h> #define N 30005 int a[N]; int stack[N]; int dp[N]; int maxx; void LIS(int n) { memset(dp,0,sizeof(dp)); memset(stack,0,sizeof(stack)); int top=0; maxx=-1; stack[top]=-1; for(int i=1;i<=n;i++) { if(a[i]>=stack[top]) { stack[++top]=a[i]; dp[i]=top; } else { int l=1,r=top; while(l<=r) { int mid=(l+r)>>1; if(a[i]<=stack[mid]) r=mid-1; else l=mid+1; } stack[l]=a[i]; dp[i]=r; } if(dp[i]>maxx) maxx=dp[i]; } } int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) scanf("%d",&a[i]); LIS(n); printf("%d\n",maxx); } return 0; }