# LIS N^2&nlogn Templates

Source: Internet
Author: User

LIS Nlogn Template http://acm.hdu.edu.cn/showproblem.php?pid=1950

`#include <iostream>#include<stdio.h>#include<algorithm>#include<string>#include<math.h>#include<stdlib.h>#defineMAXN 40000+10using namespacestd;intA[maxn],d[maxn],len;intBsinti) {    intL,r,mid; L=0, r=Len;  while(l<S) {Mid= (l+r)/2; if(D[mid]>=a[i]) r=mid; ElseL=mid+1; }    returnl;}intMain () {intT,n; scanf ("%d",&T);  while(t--) {scanf ("%d",&N);  for(intI=1; i<=n;i++) scanf ("%d",&A[i]); d[1]=a[1]; Len=1;  for(intI=2; i<=n;i++){            if(a[i]>D[len]) d[++len]=A[i]; Else{                intPos=lower_bound (D,d+len,a[i])-D; D[pos]=a[i];//find >=a[i] and update}} printf ("%d\n", Len); }    return 0;}`

LIS n^2 Template http://poj.org/problem?id=2533

`#include <iostream>#include<cstring>#include<cstdlib>#include<stdio.h>#include<algorithm>#include<math.h>#defineINF 0x3f3f3f3f#defineMAXN 10000+10using namespacestd;intA[MAXN],N,DP[MAXN];intMain () { while(cin>>N) {        intlen=-1;  for(intI=1; i<=n;i++) scanf ("%d",&A[i]); dp[0]=-INF;  for(intI=1; i<=n;i++) {Dp[i]=1;  for(intj=0; j<i;j++){                if(A[i]>a[j])//when conditions are metDp[i]=max (dp[i],dp[j]+1); if(Dp[i]>len) len=Dp[i]; }} printf ("%d\n", Len); }    return 0;}`

LIS N^2&nlogn Templates

Related Keywords:

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.