Files
python/TangDou/XiTi/1274.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

45 lines
848 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int a[101] = {0};
int f[101] = {1};
int main() {
//输入+输出重定向
freopen("../1274.txt", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
//初始值
int res = 0;
for (int i = 1; i <= n; i++) { //遍历每一个元素
f[i] = 1;
for (int j = 1; j < i; j++) {
if (a[j] > a[i] && f[j] + 1 > f[i]) {
f[i] = f[j] + 1;
}
}
}
//输出dp表
for (int i = 1; i <= n; i++) {
cout << f[i] << " ";
//将最小的dp[i]的值记录到res里
res = max(res, f[i]);
}
cout << endl;
//输出res
cout << res << endl;
//关闭文件
fclose(stdin);
return 0;
}