0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:11:58 +00:00

1259. 【例9.3】求最长不下降序列

http://ybt.ssoier.cn:8088/statusx.php?runidx=15557056
This commit is contained in:
Baoshuo Ren 2022-04-01 17:10:42 +08:00
parent 733514751c
commit 50e83048ff
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

45
ybt/1259/1259.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 205;
int n, a[N], f[N], r[N], t, ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[i] = 1;
for (int j = 1; j < i; j++) {
if (a[i] >= a[j]) f[i] = std::max(f[i], f[j] + 1);
}
if (f[i] > ans) {
ans = f[i];
t = i;
}
}
cout << "max=" << ans << endl;
for (int i = t; i; i--) {
if (f[i] == ans && a[i] <= a[t]) {
f[i] = 0;
ans--;
t = i;
}
}
for (int i = 1; i <= n; i++) {
if (!f[i]) cout << a[i] << ' ';
}
cout << endl;
return 0;
}