POJ-2533 最长上升子序列

这题没啥难度, 很简单的一题dp

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
#include <iostream>
#include <cstring>
using namespace std;

int data[1010];
int dp[1010];

int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> data[i];
}

fill(dp, dp+1010, 1);

/**
* dp[i] 表示 以 i 为最后一个元素 的最长上升子序列的长度
*/

int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (data[i] > data[j]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
ans = max(ans, dp[i]);
}

cout << ans << endl;



return 0;
}
Author: comwrg
Link: https://comwrg.github.io/2019/03/23/POJ-2533/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.