50分RE求助!!!

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

AXIS_PLAYER @ 2024-07-16 11:20:12

#include<bits/stdc++.h>
using namespace std;
int n,a[39001],b[39001],dp[3001][3001]; 
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++){
            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 xiao7_Mr_10_ @ 2024-07-16 11:23:21

哥们你数组越界了,范围很大,这道题不是直接暴力dp,转化即可


by AXIS_PLAYER @ 2024-07-16 11:24:48

好的,谢谢佬


by AXIS_PLAYER @ 2024-07-16 11:25:02

可是怎么搞啊。


by time_Amun @ 2024-07-24 16:23:38

用dp优化


by time_Amun @ 2024-07-24 16:23:48

2分


|