提交时间:2023-11-25 10:35:23
运行 ID: 112124
#include <bits/stdc++.h> using namespace std; int dp[1005]; int a[1005]; int main() { int n; cin >> n; for(int i = 1;i <= n;i++) cin >> a[i]; int m = 0; for(int i = 0;i < n;i++) { dp[i] = 1; for(int j = 0;j < i;j++) { if(a[i] >= a[j]) dp[i] = max(dp[i] , dp[j] + 1); } m = max(m , dp[i]); } cout << "max=" << m << endl; int b[1005]; int c = 0; for(int i = n - 1;i >= 0;i--) { if(dp[i] == m) { b[c] == a[i]; c++; m--; } } for(int i = c - 1;i >= 0;i--) cout << b[i] << " "; return 0; }