POJ 2533 Longest Ordered Subsequence

Source: Internet
Author: User

Longest Ordered SubsequenceTime Limit: 2000 MS Memory Limit: 65536 KTotal Submissions: 25229 Accepted: 10957 Description A numeric sequence of ai is ordered if a1 <a2 <... <. let the subsequence of the given numeric sequence (a1, a2 ,..., aN) be any sequence (ai1, ai2 ,..., aiK), where 1 <= i1 <i2 <... <iK <= N. for example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g ., (1, 7), (3, 4, 8) and other others. all longest ordered subsequences are of length 4, e. g ., (1, 3, 5, 8 ). your program, when given the numeric sequence, must find the length of its longest ordered subsequence. input The first line of input file contains the length of sequence N. the second line contains the elements of sequence-N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000 Output file must contain a single integer-the length of the longest ordered subsequence of the given sequence. sample Input 71 7 3 5 9 4 8 Sample Output 4 Source Northeastern Europe 2002, Far-Eastern Subregion longest ascending subsequence [cpp] # include <stdio. h> # include <math. h> # include <string. h> int a [1100], n; int main () {int find (); int I, j, m, s, t, max; scanf ("% d ", & n); for (I = 0; I <= n-1; I ++) {scanf ("% d", & a [I]);} max = find (); printf ("% d \ n", max); return 0;} int find () {int I, j, dp [1100], max; apsaradb for memset (dp, 0, sizeof (dp); dp [0] = 1; for (I = 1; I <= n-1; I ++) {max = 0; for (j = 0; j <= I-1; j ++) {if (a [I]> a [j]) {if (dp [j]> max) {max = dp [j] ;}} dp [I] = max + 1 ;}for (I = 0, max = 0; I <= n-1; I ++) {if (dp [I]> max) {max = dp [I] ;}} return max ;}

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.