Tên đăng nhập

K28TIN23

Họ và tên

Phùng Nhật Minh

Email

minhphungnhat506@gmail.com

Chữ ký cá nhân

#include <bits/stdc++.h> using namespace std;

#define nmax 1001 long long n, a[nmax], f[nmax], trace[nmax];

int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

cin >> n;

for (int i = 1; i <= n; i++)
    cin >> a[i];

for (int i = 1; i <= n; i++) {
    f[i] = 1;
    trace[i] = 0;
    for (int j = 1; j < n; j++)
        if (a[j] < a[i] && f[j] + 1 > f[i]) {
            f[i] = f[j] + 1;
            trace[i] = j;
        }
}

int m = 1;
for (int i = 2; i <= n; i++) {
    if (f[i] > f[m])
        m = i;
}

vector<int> b;
while (m > 0) {
    b.push_back(a[m]);
    m = trace[m];
}
reverse(b.begin(), b.end());

cout << b.size() << '\n';
for (int x : b)
    cout << x << ' ';

}

Đăng ký lúc

2022-10-01 8:39:42

Thống kê

Bài viết

Người dùng này chưa đăng bài

Kỳ thi

Kỳ thi Xếp hạng Điểm
K28 Beginner Contest 07 27 / 35 1402 (-72)
K28 Beginner Contest 05 7 / 37 1474 (+81)
K28 Beginner Contest 04 16 / 35 1393 (+5)
K28 Beginner Contest 03 22 / 33 1388 (-40)
K28 Beginner Contest 02 35 / 38 1428 (-91)
K28 Beginner Contest 01 12 / 40 1519 (+19)
Điểm ban đầu 1500