AcWing 895. 最长上升子序列 C
原题链接
简单
作者:
LaChimere
,
2021-06-04 12:06:39
,
所有人可见
,
阅读 255
C
#include <stdio.h>
#define MAXSIZE 1010
#define max(a,b) ((a)>(b)?(a):(b))
int n, nums[MAXSIZE], dp[MAXSIZE];
void init() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", nums+i);
}
}
int main() {
init();
int res = 0;
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
for (int j = 1; j < i; ++j) {
if (nums[j] < nums[i]) {
dp[i] = max(dp[i], dp[j]+1);
}
}
res = max(res, dp[i]);
}
printf("%d\n", res);
return 0;
}