LIS-NLGK.txt

# LIS-NLGK.txt - int f=0,l=best-1,m while(true m=(f l/2...

This preview shows pages 1–2. Sign up to view the full content.

Sheet1 Page 1 #include <iostream> using namespace std #define MAX 100 int arr[MAX] int dp[MAX] int pred[MAX] int ind[MAX] int n int best void print(int i) { if (i==-1) return print(pred[i]) cout<<arr[i]<<" " } int main() { { for (int i=0 i<n i++) cin>>arr[i] dp[0]=arr[0] best=1 pred[0]=-1 ind[0]=0 for (int i=1 i<n i++) { if (arr[i]<dp[0]) { dp[0]=arr[i] ind[0]=i pred[i]=-1 } else if (arr[i]>dp[best-1]) { dp[best]=arr[i] ind[best]=i pred[i]=ind[best-1] best++ } else {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int f=0,l=best-1,m while (true) { m=(f+l)/2 if (arr[i]==dp[m]) break if (arr[i]<dp[m]) { if (arr[i]==dp[m-1]) Sheet1 Page 2 break if (arr[i]<dp[m-1]) { l=m-1 continue } else { dp[m]=arr[i] ind[m]=i pred[i]=ind[m-1] } } else { if (arr[i]==dp[m+1]) break if (arr[i]>dp[m+1]) { f=m+1 continue } else { dp[m+1]=arr[i] ind[m+1]=i pred[i]=ind[m] } } } } } print(ind[best-1]) cout<<endl } return 0 }...
View Full Document

## This note was uploaded on 11/19/2009 for the course SCIENTIFIC 101 taught by Professor Maaa during the Spring '09 term at ASU.

### Page1 / 2

LIS-NLGK.txt - int f=0,l=best-1,m while(true m=(f l/2...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online