CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    16

    how to construct all LIS

    Code:
    #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 ??

  2. #2
    Join Date
    Dec 2009
    Posts
    145

    Re: how to construct all LIS

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured