//Accepted    15880 KB    250 ms
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 using namespace std;
 ;
 ;
 ;
 int dp[imax_n][imax_n];
 int addcost[imax_m];
 int deletecost[imax_m];
 int n;
 int m;
 char s[imax_n];
 int min(int a,int b)
 {
     return a<b?a:b;
 }
 void Dp()
 {
     memset(dp,,sizeof(dp));
     //for (int i=1;i<=n;i++)
     //dp[i][i]=0;
     ;l<=n;l++)
     {
         ;i<=n;i++)
         {
             ;
             dp[i][j]=inf;
             ]==s[j-]) dp[i][j]=dp[i+][j-];
             dp[i][j]=min(dp[i][j],dp[i+][j]+addcost[s[i-]-'a']);
             dp[i][j]=min(dp[i][j],dp[i+][j]+deletecost[s[i-]-'a']);
             dp[i][j]=min(dp[i][j],dp[i][j-]+addcost[s[j-]-'a']);
             dp[i][j]=min(dp[i][j],dp[i][j-]+deletecost[s[j-]-'a']);
         }
     }
     printf(][n]);
 }
 int main()
 {
     //while (scanf("%d%d",&m,&n)!=EOF)
     {
         scanf("%d%d",&m,&n);
         scanf("%s",s);
         ];
         memset(addcost,,sizeof(addcost));
         memset(deletecost,,sizeof(deletecost));
         ;i<=m;i++)
         {
             scanf("%s",ss);
             scanf(]-]-'a']);
         }
         Dp();
     }
     ;
 }

poj3280 区间dp的更多相关文章

  1. Cheapest Palindrome [POJ3280] [区间DP] [经典]

    一句话题意:每个字母添加和删除都相应代价(可以任意位置 增加/删除),求把原串变成回文串的最小代价 Description 保持对所有奶牛的跟踪是一项棘手的任务,因此农场主约翰已经安装了一个系统来实现 ...

  2. [poj3280]Cheapest Palindrome_区间dp

    Cheapest Palindrome poj-3280 题目大意:给出一个字符串,以及每种字符的加入代价和删除代价,求将这个字符串通过删减元素变成回文字符串的最小代价. 注释:每种字符都是小写英文字 ...

  3. 区间dp总结篇

    前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...

  4. 区间DP的摸索

    (poj真的炸了,以下代码可能有误) 按照下面这个做题顺序,对区间DP不再那么迷了 LOJ1422 是 dp[i][j]=min(dp[i][j],dp[i+1][k-1]+dp[k][j])而不是d ...

  5. 【BZOJ-4380】Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  6. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  7. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  8. BZOJ1055: [HAOI2008]玩具取名[区间DP]

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Statu ...

  9. poj2955 Brackets (区间dp)

    题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...

随机推荐

  1. <mvc:annotation-driven />

    <mvc:annotation-driven/>相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个 ...

  2. 【Problem solved】发现输入法都是仅桌面使用,无法输入中文时

    你打开命令提示符输入CTFMON就可以啦.

  3. css3属性 transition transform

    1.transition 译:过渡,转变 可以设置过渡属性 transition: property duration timing-function delay; transition-proper ...

  4. 5.7 WebDriver API实例讲解

    本节主要详细描述WebDriver的常用API使用方法. 1.访问某网页地址 被测试网页的网址:http://www.sogou.com. Java语言版本的API实例代码: 方法1: public ...

  5. js字符串函数之indexOf()

    indexOf 返回字符串中指定字符首次出现的位置 var str="hello, I am Miss bean!"; str.indexOf("l")//结果 ...

  6. Rectangle Intersection Test (with C#)

    Rectangle Intersection Test (with C#) by Sebastian Krysmanskihttp://manski.net/2011/05/rectangle-int ...

  7. 121. 122. 123. 188. Best Time to Buy and Sell Stock *HARD* 309. Best Time to Buy and Sell Stock with Cooldown -- 买卖股票

    121. Say you have an array for which the ith element is the price of a given stock on day i. If you ...

  8. EasyUI DataGrid View

    http://www.jeasyui.com/easyui/datagrid-detailview.js 前提一定要引入:datagrid-detailview.js主要是三个属性和普通的datgag ...

  9. shell脚本流程搭建

    程序中删除文件夹即用rm -rf ${Dir} rm -f ${Dir}/* rm -f ${Dir}* 的时候要注意先检查路径变量是否有定义不为空. if [ ! -z ${LogDir} ]; t ...

  10. JDE修改Grid列样式

    Set Grid Color :to change the background color of a cell, row, column, or the entire control. Set Gr ...