初级守护
题目链接: 酷町堂:4879
0分,哪位大佬帮我看一下?
#include <bits/stdc++.h>
using namespace std;
int n,a[1005],f[1005][1005],ans,m,b[1005],z;
string s,x,y;
bool f1;
int main(){
cin>>n;
cin>>s;
s = " " + s;
for(int i = 1;i <= n;i++){
cin>>a[i];
b[s[i]] = a[i];
}
cin>>x;
cin>>y;
n = x.length();
m = y.length();
x = " " + x;
y = " " + y;
for(int i = 1;i <= n;i++){
f1 = false;
z = 0;
for(int j = 1;j <= m;j++){
if(x[i] == y[j]){
f[i][j] = f[i - 1][j - 1] + 1;
f1 = true;
z = max(b[x[i]],z);
}else{
if(f[i - 1][j] > f[i][j - 1]) f[i][j] = f[i - 1][j];
else if(f[i - 1][j] < f[i][j - 1]) f[i][j] = f[i][j - 1];
else{
if(b[x[i]] < b[y[j]]) f[i][j] = f[i - 1][j];
else f[i][j] = f[i][j - 1];
}
}
}
if(f1) ans = ans + z;
}
cout<<ans;
return 0;
}