➤ Problem Link : ADASEQEN
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
int n,m,l1,l2;
cin>>n>>m;
map<char,ll> mp;
ll dp[n+1][m+1];
memset(dp,0,sizeof(dp));
for(int i=0;i<26;i++)
cin>>mp['a'+i];
char ar1[n+1];
char ar2[m+1];
for(int i=1;i<=n;i++)
cin>>ar1[i];
for(int i=1;i<=m;i++)
cin>>ar2[i];
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
if(i==0 || j==0)
dp[i][j]=0;
else if(ar1[i]==ar2[j])
dp[i][j]=mp[ar1[i]]+dp[i-1][j-1];
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
cout<<dp[n][m];
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
