提交时间:2023-11-25 10:39:43

运行 ID: 112135

#include <bits/stdc++.h> using namespace std; int dp[1005]; int a[1005]; int main() { int n; while(~scanf("%d" , a + n + 1)) { n++; } 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; }