1 条题解
-
1昌孝阳 (changxiaoyang) LV 10 @ 2023-10-1 19:45:53
怪基盗德
#include<iostream> using namespace std; #include<vector> #include<algorithm> #include<string.h> #include<string> #include<unordered_map> #include<math.h> #include<queue> #include<stack> const int N = 1010; int f[N], h[N], d[N]; int main() { int n,m; cin >> m; while (m--) { cin >> n; for (int i = 0; i < n; i++) cin >> h[i]; f[0] = 1; d[0] = 1; int res = 0; for (int i = 1; i < n; i++) { f[i] = 1; for (int j = i - 1; j >= 0; j--) { if (h[i] > h[j]) { f[i] = max(f[i], f[j] + 1); } } res = max(res, f[i]); } for (int i = n - 1; i >= 0; i--) { d[i] = 1; for (int j = i + 1; j < n; j++) { if (h[i] > h[j]) { d[i] = max(d[i], d[j] + 1); } } res = max(res, d[i]); } cout << res << endl; } return 0; }
- 1
信息
- ID
- 2964
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 156
- 已通过
- 27
- 上传者