45 lines
848 B
C++
45 lines
848 B
C++
#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;
|
||
}
|