Hdu 3998 (maximum number of ascending subsequences plus sequences)

Source: Internet
Author: User

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;
}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.