源代码:
#include <iostream>
#define MAXN 100005
using namespace std;
int n, n1[MAXN], n2[MAXN], dp[MAXN][MAXN];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> n1[i];
for (int i = 1; i <= n; i++)
cin >> n2[i];
for (int i1 = 1; i1 <= n; i1++)
{
for (int i2 = 1; i2 <= n; i2++)
{
if (n1[i1] == n2[i2])
{
dp[i1][i2] = dp[i1 - 1][i2 - 1] + 1;
}
else
{
dp[i1][i2] = max(dp[i1 - 1][i2], dp[i1][i2 - 1]);
}
}
}
cout << dp[n][n];
return 0;
}
在本地运行成功(VSCode + GCC 13.2.0)
PS C:\Users\JN\Desktop\learn-algorithm> & 'c:\Users\JN\.vscode\extensions\ms-vscode.cpptools-1.23.5-win32-x64\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-nvb0fvmh.c0o' '--stdout=Microsoft-MIEngine-Out-ftd20mee.gbf' '--stderr=Microsoft-MIEngine-Error-5yjc5gm2.wss' '--pid=Microsoft-MIEngine-Pid-gqa53hod.w32' '--dbgExe=C:\Program Files\Scoop\shims\gdb.exe' '--interpreter=mi'
5
3 2 1 4 5
1 2 3 4 5
3
PS C:\Users\JN\Desktop\learn-algorithm> //这里在等待输入
洛谷编译信息:
No valid executable file was produced by the compiler
./cc4I7Oqs.o: in function `_GLOBAL__sub_I_src':
src:(.text.startup+0x197): relocation truncated to fit: R_X86_64_PC32 against `.bss'
src:(.text.startup+0x1b1): relocation truncated to fit: R_X86_64_PC32 against `.bss'
collect2: 错误:ld 返回 1