为蛤报错

P1439 【模板】最长公共子序列

AAAuc03 @ 2024-11-09 18:40:17

#include<bits/stdc++.h>
using namespace std;
long long n,dp[100005][100005],a[100005],b[100005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    for(long long i=1;i<=n;i++)cin>>a[i];
    for(long long i=1;i<=n;i++)cin>>b[i];
    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=n;j++)
        {
            if(a[i]==b[j])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    cout<<dp[n][n];
    return 0;
}

by queenbee @ 2024-11-09 18:47:33

dp数组炸了


|