Code_Rime @ 2024-10-22 11:39:18
不知道哪里错了,在力扣是过的
//力扣1143
#include<iostream>
using namespace std;
#define int long long
#define maxn 300010
int text1[maxn],text2[maxn],n;
int longestCommonSubsequence(int text1[], int text2[])
{
int dp[n+1][n+1];
dp[0][0] = text1[0] == text2[0] ? 1 : 0;
for(int i = 1;i < n;i++)
{
if(text1[i] != text2[0] && dp[0][i-1] == 0)
dp[0][i] = 0;
else
dp[0][i] = 1;
}
for(int i = 1;i < n;i++)
{
if(text2[i] != text1[0] && dp[i-1][0] == 0)
dp[i][0] = 0;
else
dp[i][0] = 1;
for(int j = 1;j < n;j++)
{
if(text2[i] == text1[j])
dp[i][j] = dp[i-1][j-1] + 1;
else
dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
}
}
return dp[n-1][n-1];
}
main()
{
cin >> n;
for(int i = 0; i < n ;i++)
cin >> text1[i];
for(int i = 0; i < n ;i++)
cin >> text2[i];
cout << longestCommonSubsequence(text1,text2);
}
by Code_Rime @ 2024-10-22 16:02:30
@Code_Rime 而且无论在哪编译,都无法编译,还不知道问题所在,不显示ψ(*`ー´)ψ
by cengzh @ 2024-10-22 23:44:43
@Code_Rime 还是建议看题解,O(n^2)过不了此题
by Code_Rime @ 2024-10-23 06:48:49
@cengzh 好的,谢谢
by M_lzy @ 2024-12-13 19:48:33
@crz_qwq您能不能帮我找一个能把代码写成这样的AI?