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

价值最小回文字符串 题目大意:给你一个字符串,可以删除可以添加,并且每一次对一个字母的操作都带一个权,问你转成回文串最优操作数. 如果这一题我这样告诉你,你毫无疑问知道这一题是LD(Levenshtien Distance 编辑距离),但是上面太多废话了,理解起来还是要有点费劲,比如我一开始就觉得回文串只能从头或者尾添加(英语吃了翔╮(╯▽╰)╭). 好吧,其实这一题不是水题(我的感觉),这一题挺好的,是一个带权的编辑距离问题,因为最后还是老问题,问你最小值,所以马上想到用二维矩阵,但是这一题首…
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…
Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7148   Accepted: 3452 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…
Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10943   Accepted: 5232 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…
Cheapest Palindrome 直接翻译了 Descriptions 给定一个字符串S,字符串S的长度为M(M≤2000),字符串S所含有的字符的种类的数量为N(N≤26),然后给定这N种字符Add与Delete的代价,求将S变为回文串的最小代价和. Input 第一行:两个由空格分隔的整数 N 和 M 第二行:这一行给出了恰好 M 个字符,表示初始状态下的ID字符串 接下来的 N 行:每一行给出了由空格分隔的三部分.首先是一个字符,保证出现在了输入的字符串中.接下来是两个整数,表示你增…
Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7869   Accepted: 3816 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…
个人心得:动态规划真的是够烦人的,这题好不容易写出了转移方程,结果超时,然后看题解,为什么这些题目都是这样一步一步的 递推,在我看来就是懵逼的状态,还有那个背包也是,硬是从最大的V一直到0,而这个就是从把间距为1到ch.size()全部算出来,难道 这就是动态规划,无后效性,即每一步都是最优的状态,所以把所有状况全部解决然后就可以一步一步往后面推了??值得深思 网上题解: 分析:我们知道求添加最少的字母让其回文是经典dp问题,转化成LCS求解.这个是一个很明显的区间dp 我们定义dp [ i ]…
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…
poj 3280 题意:给定一个字符串和每个字符删去和增加的代价,求使字符串变成回文串操作所需的最小代价. 题解:哇!开心!终于亲自做对了!做完这两题这个就回了.uva10739  uva 10453 #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; struct st{ int ad,de; }; st a[]; ][…
链接:http://poj.org/problem?id=3280 思路:题目给出n种m个字符,每个字符都有对应的添加和删除的代价,求出构成最小回文串的代价 dp[i][j]代表区间i到区间j成为回文串的最小代价,那么对于dp[i][j]有三种情况: 1.dp[i+1][j]表示区间i+1到区间j已经是回文串了的最小代价,那么对于s[i]这个字母,我们有两种操作,删除与添加,对应有两种代价,dp[i+1][j]+add[s[i]],dp[i+1][j]+del[s[i]],取这两种代价的最小值:…