-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj2533.c
72 lines (62 loc) · 1.27 KB
/
poj2533.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Problem: 2533, Longest Ordered Subsequence
* User: LoiteringLeo
* Memory: 4316K Time: 938MS
* Language: GCC Result: Accepted
*/
#include <stdio.h>
#define MAX_ELE 1000
int a[MAX_ELE + 1];
int c[MAX_ELE + 1][MAX_ELE + 1];
/**
* Find the Longest Ordered Subsequence in a given number sequence
*/
int los(int *a, int n)
{
int i;
int j;
int k;
int longest;
int curr_longest;
for (i = 1; i <= n; i++) {
c[1][i] = 1;
c[i][i] = 1;
}
for (j = 2; j <= n; j++) {
curr_longest = 1;
for (i = 1; i < j; i++) {
for (k = i; k < j; k++) {
if (a[j] > a[k] && curr_longest < c[i][k] + 1) {
curr_longest = c[i][k] + 1;
}
}
c[i][j] = curr_longest;
}
}
#if 0
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
printf("%d ", c[i][j]);
}
printf("\n");
}
#endif
longest = c[1][1];
for (i = 2; i <= n; i++) {
if (longest < c[1][i]) {
longest = c[1][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;
}