提交时间:2023-12-26 13:42:25

运行 ID: 117798

#include<bits/stdc++.h> using namespace std; int a[114514],dp[114514],pd[1005][1005],id,maxn; int main(){ int n = 0,x; //cin>>n; /* for (int i = 1;i <= n;i++){ cin>>a[i]; } */ while (cin>>x){ n++; a[n] = x; } dp[1] = 1; pd[1][1] = a[1]; for (int i = 2;i <= n;i++){ dp[i] = 1; pd[i][1] = a[i]; for (int j = 1;j < i;j++){ if (a[i] > a[j]){ if (dp[j] + 1 > dp[i]){ dp[i] = dp[j] + 1; for (int k = 1;k <= dp[j];k++){ pd[i][k] = pd[j][k]; } pd[i][dp[j] + 1] = a[i]; } } } if (dp[i] > maxn){ maxn = dp[i]; id = i; } } cout<<"max="<<maxn<<endl; for (int i = 1;i <= dp[id];i++){ cout<<pd[id][i]<<" "; } return 0; }