-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj2533-2.c
56 lines (48 loc) · 973 Bytes
/
poj2533-2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Problem: 2533, Longest Ordered Subsequence
* User: LoiteringLeo
* Ref: http://blog.bluebore.cn/?p=350
* Memory: 396K Time: 32MS
* Language: GCC Result:
*/
#include <stdio.h>
#define MAX_ELE 1000
int a[MAX_ELE + 1];
int max[MAX_ELE + 1];
/**
* Find the Longest Ordered Subsequence in a given number sequence
*/
int los(int *a, int n)
{
int i;
int j;
int longest;
for (i = 1; i <= n; i++) {
max[i] = 1;
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= i; j++) {
if (a[j] < a[i]) {
max[i] = (max[i] > max[j] + 1) ? max[i] : max[j] + 1;
}
}
}
longest = 1;
for (i = 1; i <= n; i++) {
if (longest < max[i]) {
longest = max[i];
}
}
return longest;
}
int main()
{
int n;
int i;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
printf("%d\n", los(a, n));
return 0;
}