提交时间:2023-11-25 09:49:15

运行 ID: 112036

#include<iostream> #include<vector> using namespace std; typedef long long ll; int n = 1, f[1010], a[1010], ans = -1e9; vector<int> vec; int main(){ while(cin >> a[n]){ n++; }n--; for(int i = 1; i <= n; i++) f[i] = 1; for(int i = 2; i <= n; i++) for(int j = 1; j < i; j++) if(a[i] >= a[j]){ f[i] = max(f[i], f[j] + 1); } for(int i = 1; i <= n; i++) ans = max(ans, f[i]); cout << "max=" << ans << endl; int st = n; for(int i = n; i >= 1; i--) if(f[i] == ans) st = i; for(int i = st; i >= 1; i--){ if(f[i] == ans - vec.size()) vec.push_back(a[i]); } for(int i = vec.size() - 1; i >= 0; i--) cout << vec[i] << ' '; return 0; }