int longest=0;
void LongestSubSeq(int* arr, int count, bool* assis, int curindx, int lastnum, int length)
{
if(curindx==count)
{
if(longest<length)
{
longest=length;
for(int i=0;i<count;++i)
if(true==assis[i])
cout<<arr[i]<<" ";
cout<<endl;
}
}
else if(curindx<count)
{
if(arr[curindx]<lastnum)
{
assis[curindx]=true;
LongestSubSeq(arr, count, assis, curindx+1, arr[curindx], length+1);
}
assis[curindx]=false;
LongestSubSeq(arr, count, assis, curindx+1, lastnum,length);
}
}
int LongestSubSeq(int* arr, int count)
{
if(NULL==arr || count==0)
return 0;
if(count<0)
return -1;
bool* assis=new bool[count];
memset(assis,0, sizeof(bool)*count);
LongestSubSeq(arr, count, assis, 0, 0x7fffffff, 0);
delete []assis;
return 0;
}
07-29