Click to See Complete Forum and Search --> : how to construct all LIS


maruf10
July 6th, 2010, 02:35 AM
#include<iostream>
#define INF 1<<20
#define min(a,b) (a<b?a:b)
#define MAX 100
using namespace std;

int B[]={-INF,INF,INF,INF,INF,INF,INF,INF,INF,INF,INF,INF};

int bin(int key)
{
int v;
int lo=0;
int hi=11;
int mid;
while(lo<=hi)
{
mid=lo+(hi-lo)/2;
if(B[mid]>key)
{
v=mid;
hi=mid-1;
}
else
lo=mid+1;
}
return v;
}

int main()
{

int i;
int arr[]={9,2,5,4,3,7,11,8,10,13,1};

int max=-1;
for(i=0;i<11;i++)
{
int pos=bin(arr[i]);
B[pos]=arr[i];
if(max<pos)max=pos;
}
cout<<max<<endl;
return 0;
}




i am using this code to print the length of LIS of arr[].how can i print all LIS ??

Ledidas
July 7th, 2010, 04:16 PM
LIS ? you mean list ?
std::copy(v.begin(),v.end(),std:: ostream_iterator<int>(std::cout, " "));
will print out a vector (array)
cout<<sizeof(arr)/sizeof(arr[0])
will display the len of arr