Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
112337 | 陈志轩 | 求最长不下降序列 | C++ | 解答错误 | 40 | 0 MS | 652 KB | 892 | 2023-11-25 16:45:32 |
#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] = 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; }