提交时间:2023-11-25 10:50:15

运行 ID: 112179

#include<bits/stdc++.h> using namespace std; int main(){ int b[201][101]; int n; cin >> n; for(int i = 1;i <= n;i++){ cin >> b[i][1]; b[i][2] = 1; b[i][3] = 0; } int l,k; for(int i = n-1;i >= 1;i--){ l = 0; k = 0; for(int j = i+1;j <= n;j++){ if(b[j][1] >= b[i][1] && b[i][2] > l) { l = b[j][2]; k = j; } if(l > 0){ b[i][2] = l+1; b[i][3] = k; } } } k = 1; for(int j = 1;j <= n;j++){ if(b[j][2] >b[k][2]){ k = j; } } cout << "max =" << b[k][2] << endl; while(k!=0){ cout << ' ' << b[k][1]; k = b[k][3]; } return 0; }