#include
<
stdio.h
>
#include < string .h >
#define MAX 256
int main( void )
{
char s[] = { 8 , 23 , 6 , 4 , 6 , 22 , 4 , 1 , 89 , 74 };
char stk[MAX];
char l[MAX];
int m[MAX];
int n;
int i, j, top, max, pos;
n = sizeof (s) / sizeof (s[ 0 ]);
l[ 0 ] = 1 ;
m[ 0 ] = - 1 ;
for (i = 1 ;i < n;i ++ )
{
max = 0 ;
pos = - 1 ;
for (j = 0 ;j < i;j ++ )
if (s[j] < s[i] && l[j] > max)
max = l[j], pos = j;
l[i] = max + 1 ;
m[i] = pos;
}
max = - 1 ;
for (i = 0 ;i < n;i ++ )
if (l[i] > max)
max = l[i],pos = i;
top = 0 ;
for (j = 0 ;j < max;j ++ )
stk[top ++ ] = pos, pos = m[pos];
printf( " the max is: %d " ,max);
while (top -- ) printf( " %d " ,stk[top]);
printf( " " );
return 0 ;
}
#include < string .h >
#define MAX 256
int main( void )
{
char s[] = { 8 , 23 , 6 , 4 , 6 , 22 , 4 , 1 , 89 , 74 };
char stk[MAX];
char l[MAX];
int m[MAX];
int n;
int i, j, top, max, pos;
n = sizeof (s) / sizeof (s[ 0 ]);
l[ 0 ] = 1 ;
m[ 0 ] = - 1 ;
for (i = 1 ;i < n;i ++ )
{
max = 0 ;
pos = - 1 ;
for (j = 0 ;j < i;j ++ )
if (s[j] < s[i] && l[j] > max)
max = l[j], pos = j;
l[i] = max + 1 ;
m[i] = pos;
}
max = - 1 ;
for (i = 0 ;i < n;i ++ )
if (l[i] > max)
max = l[i],pos = i;
top = 0 ;
for (j = 0 ;j < max;j ++ )
stk[top ++ ] = pos, pos = m[pos];
printf( " the max is: %d " ,max);
while (top -- ) printf( " %d " ,stk[top]);
printf( " " );
return 0 ;
}