From b50080a6cc7437fe28874f2b028269a81417c614 Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Fri, 4 Mar 2022 15:22:30 +0800 Subject: [PATCH] =?UTF-8?q?(50pts)=20P1439=20=E3=80=90=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E3=80=91=E6=9C=80=E9=95=BF=E5=85=AC=E5=85=B1=E5=AD=90=E5=BA=8F?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R67364851 --- Luogu/P1439/P1439.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Luogu/P1439/P1439.cpp diff --git a/Luogu/P1439/P1439.cpp b/Luogu/P1439/P1439.cpp new file mode 100644 index 00000000..0a4358b0 --- /dev/null +++ b/Luogu/P1439/P1439.cpp @@ -0,0 +1,29 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +const int N = 10005; + +int n, a[N], b[N], f[N][N]; + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + for (int i = 1; i <= n; i++) { + cin >> b[i]; + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + f[i][j] = std::max(f[i - 1][j], f[i][j - 1]); + if (a[i] == b[j]) { + f[i][j] = std::max(f[i][j], f[i - 1][j - 1] + 1); + } + } + } + cout << f[n][n] << endl; + return 0; +}