I think other people use network streams. I don't know network streams.
My method is to find the Maximum ascending subsequence normally, and then mark all the values in the sequence to mark that the data has been used. Then, continue the operation of finding the Maximum ascending subsequence of the remaining data. Until the length of the sequence cannot reach the maximum length.
In this way, the AC is built on the condition that the hdu test data is relatively weak and the data volume is relatively small. In the worst case, the time complexity is O (n ^ 3 ).
Codeblocks debug is still not used.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Define N 500
Struct node
{
Int x, pre;
Int count;
} A [N];
Int mark [N];
Int main ()
{
Int n;
Int I, j, ans;
Int count;
While (scanf ("% d", & n )! = EOF)
{
For (I = 0; I <n; I ++)
{
Scanf ("% d", & a [I]. x );
A [I]. pre = I;
A [I]. count = 1;
Mark [I] = 0;
}
For (I = 0; I <n; I ++)
{
For (j = 0; j <I; j ++)
{
If (a [j]. x <a [I]. x & a [j]. count> = a [I]. count)
{
A [I]. count = a [j]. count + 1;
A [I]. pre = j;
}
}
}
Ans = 0;
Int temp;
For (I = 0; I <n; I ++)
{
If (ans <a [I]. count)
{
Ans = a [I]. count;
Temp = I;
}
}
Int x;
X = temp;
While (1)
{
Mark [x] = 1;
If (a [x]. pre = x)
Break;
X = a [x]. pre;
}
Count = 1;
Int ss;
Ss = ans;
While (ans = ss)
{
For (I = 0; I <n; I ++)
{
A [I]. count = 1;
A [I]. pre = I;
}
For (I = 0; I <n; I ++)
{
If (mark [I] = 1)
Continue;
For (j = 0; j <I; j ++)
{
If (mark [j] = 1)
Continue;
If (a [j]. x <a [I]. x & a [j]. count> = a [I]. count)
{
A [I]. count = a [j]. count + 1;
A [I]. pre = j;
}
}
}
Ans = 0;
Int temp;
For (I = 0; I <n; I ++)
{
If (mark [I] = 1)
Continue;
If (ans <a [I]. count)
{
Ans = a [I]. count;
Temp = I;
}
}
If (ans = ss)
Count ++;
Int x;
X = temp;
While (1)
{
Mark [x] = 1;
If (a [x]. pre = x)
Break;
X = a [x]. pre;
}
}
Printf ("% d \ n", ss );
Printf ("% d \ n", count );
}
Return 0;
}
# Include <stdio. h>
# Include <string. h>
# Define N 500
Struct node
{
Int x, pre;
Int count;
} A [N];
Int mark [N];
Int main ()
{
Int n;
Int I, j, ans;
Int count;
While (scanf ("% d", & n )! = EOF)
{
For (I = 0; I <n; I ++)
{
Scanf ("% d", & a [I]. x );
A [I]. pre = I;
A [I]. count = 1;
Mark [I] = 0;
}
For (I = 0; I <n; I ++)
{
For (j = 0; j <I; j ++)
{
If (a [j]. x <a [I]. x & a [j]. count> = a [I]. count)
{
A [I]. count = a [j]. count + 1;
A [I]. pre = j;
}
}
}
Ans = 0;
Int temp;
For (I = 0; I <n; I ++)
{
If (ans <a [I]. count)
{
Ans = a [I]. count;
Temp = I;
}
}
Int x;
X = temp;
While (1)
{
Mark [x] = 1;
If (a [x]. pre = x)
Break;
X = a [x]. pre;
}
Count = 1;
Int ss;
Ss = ans;
While (ans = ss)
{
For (I = 0; I <n; I ++)
{
A [I]. count = 1;
A [I]. pre = I;
}
For (I = 0; I <n; I ++)
{
If (mark [I] = 1)
Continue;
For (j = 0; j <I; j ++)
{
If (mark [j] = 1)
Continue;
If (a [j]. x <a [I]. x & a [j]. count> = a [I]. count)
{
A [I]. count = a [j]. count + 1;
A [I]. pre = j;
}
}
}
Ans = 0;
Int temp;
For (I = 0; I <n; I ++)
{
If (mark [I] = 1)
Continue;
If (ans <a [I]. count)
{
Ans = a [I]. count;
Temp = I;
}
}
If (ans = ss)
Count ++;
Int x;
X = temp;
While (1)
{
Mark [x] = 1;
If (a [x]. pre = x)
Break;
X = a [x]. pre;
}
}
Printf ("% d \ n", ss );
Printf ("% d \ n", count );
}
Return 0;
}