Login
Register
Problem list
Online status
Westbrook
:
2024-05-11 10:58:24
#include
#include
#include
using namespace std; const int N = 1e5 + 10; int a[N]; int f[N]; int m; int main() { cin >> m; while (m--) { memset(a, 0, sizeof a); memset(f, 0, sizeof f); int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { f[i] = 1; for (int j = 1; j < i; j++) { if (a[j] <= a[i]) { f[i] = max(f[i], f[j] + 1); } } } int res = 0; for (int i = 1; i <= n; i++) { res = max(res, f[i]); } cout << res << endl; } return 0; }样例不需要优化,需要注意初始化以及相等也加进去的情况
Westbrook
:
2024-04-26 10:45:23
#include
#include
using namespace std; const int N = 10010; int f[N]; int a[N]; int m, n; int main() { cin >> m; while (m--) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int cnt = 0; f[cnt++] = a[0]; for (int i = 1; i < n; i++) { if (a[i] > f[cnt - 1]) f[cnt++] = a[i]; else { int l = 0, r = cnt - 1; while (l < r) { int mid = (l + r) >> 1; if (f[mid] >= a[i]) r = mid; else l = mid + 1; } f[r] = a[i]; } } cout << cnt << endl; } return 0; }// 实在不理解哪错了
Post Your Comment