题目链接

被以前的题目惯性思维了,此题dp[i][j],代表i到j这一段变成回文的最小花费。我觉得挺难的理解的。

 #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int dp[][];
char s1[];
int hash[];
int main()
{
int n,m,i,j,a,b;
char ch[];
while(scanf("%d%d",&n,&m)!=EOF)
{
scanf("%s",s1);
memset(dp,,sizeof(dp));
for(i = ;i <= n;i ++)
{
scanf("%s%d%d",ch,&a,&b);
hash[ch[]-'a'] = min(a,b);
}
for(i = m;i >= ;i --)
{
for(j = i;j <= m;j ++)
{
if(s1[i-] == s1[j-])
{
dp[i][j] = dp[i+][j-];
}
else
{
dp[i][j] = min(dp[i+][j]+hash[s1[i-]-'a'],dp[i][j-]+hash[s1[j-]-'a']);
}
}
}
printf("%d\n",dp[][m]);
}
return ;
}
/*
2 5
bbaab
a 1 2
b 10 10
*/

POJ 3280 Cheapest Palindrome(DP)的更多相关文章

  1. poj 3280 Cheapest Palindrome ---(DP 回文串)

    题目链接:http://poj.org/problem?id=3280 思路: dp[i][j] :=第i个字符到第j个字符之间形成回文串的最小费用. dp[i][j]=min(dp[i+1][j]+ ...

  2. POJ 3280 Cheapest Palindrome DP题解

    看到Palindrome的题目.首先想到的应该是中心问题,然后从中心出发,思考怎样解决. DP问题通常是从更加小的问题转化到更加大的问题.然后是从地往上 bottom up地计算答案的. 能得出状态转 ...

  3. POJ 3280 Cheapest Palindrome(DP 回文变形)

    题目链接:http://poj.org/problem?id=3280 题目大意:给定一个字符串,可以删除增加,每个操作都有代价,求出将字符串转换成回文串的最小代价 Sample Input 3 4 ...

  4. POJ 3280 - Cheapest Palindrome - [区间DP]

    题目链接:http://poj.org/problem?id=3280 Time Limit: 2000MS Memory Limit: 65536K Description Keeping trac ...

  5. POJ 3280 Cheapest Palindrome(区间DP求改成回文串的最小花费)

    题目链接:http://poj.org/problem?id=3280 题目大意:给你一个字符串,你可以删除或者增加任意字符,对应有相应的花费,让你通过这些操作使得字符串变为回文串,求最小花费.解题思 ...

  6. (中等) POJ 3280 Cheapest Palindrome,DP。

    Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system ...

  7. POJ 3280 Cheapest Palindrome(DP)

    题目链接 题意 :给你一个字符串,让你删除或添加某些字母让这个字符串变成回文串,删除或添加某个字母要付出相应的代价,问你变成回文所需要的最小的代价是多少. 思路 :DP[i][j]代表的是 i 到 j ...

  8. POJ 3280 Cheapest Palindrome 简单DP

    观察题目我们可以知道,实际上对于一个字母,你在串中删除或者添加本质上一样的,因为既然你添加是为了让其对称,说明有一个孤立的字母没有配对的,也就可以删掉,也能满足对称. 故两种操作看成一种,只需要保留花 ...

  9. POJ 3280 Cheapest Palindrome (DP)

     Description Keeping track of all the cows can be a tricky task so Farmer John has installed a sys ...

随机推荐

  1. HDOJ 1863 prim算法 HDOJ 1879

    #include<cstdio> #include<cstring> #define inf 0xffffff ][]; int ans; void prim(int n) { ...

  2. neutron 中 flat vlan gre vxlan的区别

    In a flat network, everyone shares the same network segment. For example, say 2 tenants are sharing ...

  3. Junit4测试

    1.junit初级入门 2.常用注解 3.运行流程 4.测试套件使用 5.参数化设置

  4. PHP实现 bitmap 位图排序 求交集

    2014年12月16日 17:15:09 初始化一串全为0的二进制; 现有一串无序的整数数组; 如果整数x在这个整数数组当中,就将二进制串的第x位置为1; 然后顺序读取这个二进制串,并将为1的位转换成 ...

  5. VS2013+opencv2.4.9(10)配置

    1. 下载opencv2.4.9,然后解压到一个位置 设置opencv SDK解压目录,点击Extract后解压   我是习惯于解压到这个位置的.   解压过程如上图.  2. 文件目录介绍  解压后 ...

  6. cf50A(水题)

    题意:m*n的地板最多能铺多少2*1的地板砖,不能重复... 水题.. 上代码... #include <iostream> #include <stdio.h> using ...

  7. ListView滑动删除效果实现

    通过继承ListView然后结合PopupWindow实现 首先是布局文件: delete_btn.xml:这里只需要一个Button <?xml version="1.0" ...

  8. svn: warning: 'xxxxxx' is already under version control

    [root@NGINX-APACHE-SVN pm]# svn status ? plugins ? files ? images ? data ? resources [root@NGINX-APA ...

  9. poj 1273 最大流入门

    明天再拍一遍 #include <iostream> #include <queue> using namespace std; ; const int INF = 0x7FF ...

  10. 利用Roslyn把C#代码编译到内存中并进行执行

    Tugberk Ugurlu在其博文<Compiling C# Code Into Memory and Executing It with Roslyn>中给大家介绍了一种使用.NET下 ...