编程介的小学生 2017-03-04 14:43 采纳率: 20.5%
浏览 733
已采纳

Match for Bonus

Roy played a game with his roommates the other day.

His roommates wrote 2 strings of characters, and gave each character a bonus value. When Roy pinned the positions of one common character in the 2 strings, the bonus value of that character would be added to Roy's score. However at the mean time, the 2 characters and those before them in the strings would be erased.

Roy now needs your help, because he wants to know the maximum score he can get.

Input

There are several test cases.

For each test case, the first line contains an integer N.

The following N lines describe a list of N characters and their bonus values.

Then the following 2 lines give the 2 strings.

Output

For each test case, output in one line the best score Roy can get.

Sample Input

3
a 1
b 1
c 1
abc
bca
3
a 1
b 10
c 100
abc
cab

Sample Output

2
100

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-10 14:56
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化