Problem 1001Time Limit:1 Sec Memory Limit:128 MBSubmit:33 So

1个回答

  • ;

    using namespace std;

    #define MIN(a,b) ((a)#define MAX(a,b) ((a)>(b))?(a):(b)

    int point[27];

    char ch[27];

    char d[5001];//开小了

    char p[5001];

    int dp[2][5001];

    int main(){

    int n,i,j,k;

    while(scanf("%d",&n)!=EOF){

    scanf("%s",&ch);

    int t;

    for(i=0;i

    scanf("%d",&t);

    point[ch[i]-'a']=t;

    }

    scanf("%s",d+1);

    scanf("%s",p+1);

    memset(dp,0,sizeof(dp));

    int tmp=0;

    for(i=1;d[i];i++){

    for(j=1;p[j];j++){

    if(d[i]==p[j])

    dp[tmp][j]=dp[!tmp][j-1]+point[d[i]-'a'];

    else{

    dp[tmp][j]=MAX(dp[tmp][j-1],dp[!tmp][j]);

    }

    }

    tmp=!tmp;

    }

    cout<

    }

    return 0;

    }