1. 程式人生 > >POJ-3280 Cheapest Palindrome DP 鶸的DP解題報告

POJ-3280 Cheapest Palindrome DP 鶸的DP解題報告

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 single string with length M (1 ≤ M ≤ 2,000) characters drawn from an alphabet of N

 (1 ≤ N ≤ 26) different symbols (namely, the lower-case roman alphabet).

Cows, being the mischievous creatures they are, sometimes try to spoof the system by walking backwards. While a cow whose ID is "abcba" would read the same no matter which direction the she walks, a cow with the ID "abcb" can potentially register as two different IDs ("abcb" and "bcba").

FJ would like to change the cows's ID tags so they read the same no matter which direction the cow walks by. For example, "abcb" can be changed by adding "a" at the end to form "abcba" so that the ID is palindromic (reads the same forwards and backwards). Some other ways to change the ID to be palindromic are include adding the three letters "bcb" to the begining to yield the ID "bcbabcb" or removing the letter "a" to yield the ID "bcb". One can add or remove characters at any location in the string yielding a string longer or shorter than the original string.

Unfortunately as the ID tags are electronic, each character insertion or deletion has a cost (0 ≤ cost ≤ 10,000) which varies depending on exactly which character value to be added or deleted. Given the content of a cow's ID tag and the cost of inserting or deleting each of the alphabet's characters, find the minimum cost to change the ID tag so it satisfies FJ's requirements. An empty ID tag is considered to satisfy the requirements of reading the same forward and backward. Only letters with associated costs can be added to a string.

相關推薦

POJ 3280 Cheapest Palindrome(區間DP求改成回文串的最小花費)

tor color eps span algorithm har pac 操作 tac 題目鏈接:http://poj.org/problem?id=3280 題目大意:給你一個字符串,你可以刪除或者增加任意字符,對應有相應的花費,讓你通過這些操作使得字符串變為回文串,求

POJ-3280 Cheapest Palindrome 【區間DP

題目傳送門 題目: 給定一個字串S及其長度M與S所含有的字元種數N(最多26種小寫字母),然後給定這N種字母Add與Delete的代價,求將S變為迴文串的最小代價和。 題解: 對字元的增加或刪除效果是一樣的,所以我們只需要考慮增加或刪除字元的最小代價,設dp[i][j]代表區間i

POJ-3280 Cheapest Palindrome DP DP解題報告

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

POJ 3280 Cheapest Palindrome ( 區間DP && 經典模型 )

ide aps class nbsp 圖片 pri 子串 microsoft using 題意 : 給出一個由 n 中字母組成的長度為 m 的串,給出 n 種字母添加和刪除花費的代價,求讓給出的串變成回文串的代價。 分析 : 原始模型 ==> 題意和本題差不多,

POJ 3280 Cheapest Palindrome

depend content sin pri clu rds mis sts ask Keeping track of all the cows can be a tricky task so Farmer John has installed a system to a

Cheapest Palindrome(區間DP

cte oci register mat 添加 put 回文字符 medium ads 描述 Keeping track of all the cows can be a tricky task so Farmer John has installed a system

【POJ3280】Cheapest Palindrome(區間dp

題目連結 Cheapest Palindrome Time Limit: 2000MS   Memory Limit: 65536K Total Submissions:13315

POJ 2559-Largest Rectangle in a Histogram 解題報告 【笛卡爾樹與單調棧】

POJ 2559-Largest Rectangle in a Histogram 解題報告 【笛卡爾樹與單調棧】 Description   A histogram is a polygon composed of a sequence of rectang

POJ-3616 Milking Time DP解題報告

題目:Milking TimeTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 12358Accepted: 5242DescriptionBessie is such a hard-working cow. I

[luoguP2890] [USACO07OPEN]便宜的回文Cheapest PalindromeDP

span char play click aps cst 代碼 include sdi 傳送門 f[i][j] 表示區間 i 到 j 變為回文串所需最小費用 1.s[i] == s[j]  f[i][j] = f[i + 1][j - 1] 2.s[i] !=

poj - 1185 炮兵陣地 狀壓DP 解題報告

其他 無法 popu mon 多少 mod tdi 遞推關系 r+ 炮兵陣地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 21553 Accepted: 8363

臺州 OJ 1704 Cheapest Palindrome 回文 區間DP

rom iostream ostream 如果 main open size cstring memset 題目意思:給一個字符串和每個字母刪除、插入的代價,求把它變成回文串的最小代價 dp[i][j] 表示 區間 i~j 的子串變成回文串需要的最小代價。 設字符串 a

POJ 1458(DP初步_B題)解題報告

con lap %d org for opened long hid body 題目鏈接:http://poj.org/problem?id=1458 -------------------------------------------------------- 題意:給

POJ 1321(DP初步_I題)解題報告

org sin return 題意 存在 分享圖片 problem aps 題目 題目鏈接:http://poj.org/problem?id=1321 -------------------------------------------------------- 題意:

TOJ 1704: Cheapest Palindrome 區間DP

1704: Cheapest Palindrome 描述 Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He

DP E - Cheapest Palindrome

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 t

poj 1159】 Palindrome DP(類最長公共子序列)+滾動陣列

Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 58492 Accepted: 20318 Description A palindrom

POJ 3254 Corn Fields (狀壓DP)

sign inline con cout ont tor const put 方式 題意:給定一個n*m的01矩陣,然後求有多少種方式,在1上並且1不相鄰。 析:一個簡單的狀壓DP,dp[i][s] 表示 第 i 行狀態為 s 時有多少種,然後只要處理不相鄰就行了,比賽進位

POJ 1185 炮兵陣地 (狀壓DP)

pre int fine clu mat 狀態 print 優化 ans 題意:中文題。 析:dp[i][s][t] 表示第 i 行狀態為 s, 第 i-1 行為 t,然後就很簡單了,但是要超內存,實際上狀態最多才60個,所以後兩維開60就好, 然後又超時間,就一直加優化,

hdu 5375 - Gray code(dp) 解題報告

auto 當前 width ive data -i int code original Gray code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth