提交时间:2023-11-25 11:04:19
运行 ID: 112228
#include <bits/stdc++.h> using namespace std; int dp[1005]; int a[1005]; int p[1005]; int ans , mid; int print(int x) { if(x == 0) return 0; print(p[x]); cout << a[x] << " "; } int main() { int n; while(~scanf("%d" , a + n + 1)) { n++; } for(int i = 1;i <= n;i++) { int l = 0 , k = 0; for(int j = 1;j < i;j++) { if(a[j] < a[i] && l < dp[j]) { l = dp[j]; k = j; } dp[i] = l + 1; p[i] = k; if(dp[i] > ans) { ans = dp[i]; mid = i; } } } cout << "max=" << ans << endl; print(mid); return 0; }