POJ 3280 Cheapest Palindrome【DP】】的更多相关文章

题意:对一个字符串进行插入删除等操作使其变成一个回文串,但是对于每个字符的操作消耗是不同的.求最小消耗. 思路: 我们定义dp [ i ] [ j ] 为区间 i 到 j 变成回文的最小代价.那么对于dp[i][j]有三种情况首先:对于一个串如果s[i]==s[j],那么dp[i][j]=dp[i+1][j-1]其次:如果dp[i+1][j]是回文串,那么dp[i][j]=dp[i+1][j]+min(add[i],del[i]):最后,如果dp[i][j-1]是回文串,那么dp[i][j]=d…
Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6013   Accepted: 2933 Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow a…
Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will read as the cows pass by a scanner. Each ID tag's contents are currently a…
题目链接:http://poj.org/problem?id=3280 题目大意:给定一个字符串,可以删除增加,每个操作都有代价,求出将字符串转换成回文串的最小代价 Sample Input 3 4 abcb a 1000 1100 b 350 700 c 200 800 Sample Output 900 分析:这是一道最长回文串的变形,就是LCS 一串字符要变成回文,对于一个字符来说,删掉它,或者增加对称的一个该字符,都能达到回文的效果,所以是等价的.所以取代价的的时候选择最小的就可以. 至…
题目链接:http://poj.org/problem?id=3280 Time Limit: 2000MS Memory Limit: 65536K Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that th…
Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will read as the cows pass by a scanner. Each ID tag's contents are…
题目链接 题意 :给你一个字符串,让你删除或添加某些字母让这个字符串变成回文串,删除或添加某个字母要付出相应的代价,问你变成回文所需要的最小的代价是多少. 思路 :DP[i][j]代表的是 i 到 j 这一段位置变成回文所需的最小的代价. #include <stdio.h> #include <string.h> #include <iostream> using namespace std ; ] ; ] ; ][] ; int main() { int M,N ;…
观察题目我们可以知道,实际上对于一个字母,你在串中删除或者添加本质上一样的,因为既然你添加是为了让其对称,说明有一个孤立的字母没有配对的,也就可以删掉,也能满足对称. 故两种操作看成一种,只需要保留花费少的那个即可 然后 令 dp[i][j]表示从位置i到j的子串转化为回文串需要的次数 若 s[i]== s[j] 则dp[i][j] = dp[i + 1][j - 1] 否则 dp[i][j] = min(dp[i+1][j] + cost[i], dp[i][j - 1] + cost[j])…
 Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will read as the cows pass by a scanner. Each ID tag's contents…
<题目链接> 题目大意: 一个由小写字母组成的字符串,给出字符的种类,以及字符串的长度,再给出添加每个字符和删除每个字符的代价,问你要使这个字符串变成回文串的最小代价. 解题分析: 一道区间DP的好题.因为本题字符串的长度最大为2e3,所以考虑$O(n^2)$直接枚举区间的两个端点,然后对枚举的区间进行状态转移,大体上有三种转移情况: $dp[l][r]$表示$[l,r]$为回文串的最小代价 对于区间$[l,r]$,当$str[l]==str[r]$时,$dp[l][r]=dp[l+1][r-…