dp[i][j]表示将字符串子区间[i,j]转化为回文字符串的最小成本。

 1 #include<cstdio>
2 #include<algorithm>
3 #include<cstring>
4 #include<cmath>
5 #include<string>
6 #include<iostream>
7 using namespace std;
8 const int maxn=2010;
9 int n,m,dp[maxn][maxn],w[30];
10 char s[maxn];
11
12 int main(){
13 scanf("%d%d",&n,&m);
14 scanf("%s",s);
15 for(int i=1;i<=n;i++){
16 char c;
17 int k1,k2;
18 cin>>c>>k1>>k2;
19 w[c-'a']=min(k1,k2);//添加和删去效果等价,取最小的
20 }
21 for(int i=m-1;i>=0;i--){
22 for(int j=i+1;j<m;j++){//枚举区间左右端点
23 if(s[i]==s[j]) dp[i][j]=dp[i+1][j-1];
24 else dp[i][j]=min(dp[i+1][j]+w[s[i]-'a'],dp[i][j-1]+w[s[j]-'a']);
25 }
26 }
27 printf("%d",dp[0][m-1]);
28 return 0;
29 }

最新文章

  1. angular的路由
  2. 使用 Google Web Fonts
  3. 在CentOS或RHEL防火墙上开启端口
  4. 13,SFDC 管理员篇 - 移动客户端
  5. SQL 教程学习进度备忘
  6. Android系统SVC命令教程
  7. Linux基础--分类与合并命令
  8. django开发框架-view & template
  9. 网页错误404 or 500
  10. angular $digest 运行10次货10次以上会抛出异常
  11. 学习笔记TF021:预测编码、字符级语言建模、ArXiv摘要
  12. 通过kubernetes构建ela服务
  13. axaj 的回调
  14. vue 开发系列(七) 路由配置
  15. eclipse maven jdk全局设置
  16. MySQL ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39;解决
  17. POJ 1459 &amp;amp;&amp;amp; ZOJ 1734--Power Network【最大流dinic】
  18. hadoop配置文件的参数含义说明
  19. 解决Sublime包管理package control 报错 There are no packages available for installation
  20. Strut2------源码下载

热门文章

  1. C#基础-面向对象详解
  2. qbxt数学五一Day4
  3. CSS 上下居中和最低高度语法
  4. YII学习总结3(session)
  5. YII服务定位器依赖注入
  6. 我在Apache DolphinScheduler的心路历练
  7. Canvas 非线性图形(一):文本
  8. 十周周末总结 MySQL的介绍与使用
  9. HTML初学者小知识2
  10. HTML+JS+CSS 实现随机跳转到一个网址