POJ1159——Palindrome】的更多相关文章

Palindrome DescriptionA palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inser…
G - 回文串 Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program w…
Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 58277   Accepted: 20221 Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a…
Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 53647   Accepted: 18522 Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a…
一.Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into…
题目链接:http://poj.org/problem?id=1159 题意:求一个字符串加多少个字符,可以变成一个回文串.把这个字符串倒过来存一遍,求这两个字符串的lcs,用原长减去lcs就行.这题卡内存真稀奇,于是修改成滚动数组.观察发现i值的更新只有可能是从i或i-1转移来,所以就i取模2. /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mind! ┛┗┛┗┛┃\○/ ┓┏┓┏┓┃ / ┛┗┛┗┛┃ノ) ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃ ┛┗┛┗┛┃ ┓┏┓┏┓┃…
题目大意 给定一个字符串S,问最少插入多少个字符可以使字符串S变为回文串 题解 用dp[i][j]表示把字符串s[i-j]变为回文串需要插入的最小字符数 如果s[i]==s[j]那么dp[i][j]=dp[i+1][j-1] 如果s[i]!=s[j]那么dp[i][j]=min(dp[i+1][j],dp[i][j-1])+1 可以用滚动数组优化一下空间 代码: #include<cstdio> #include<algorithm> #include<cstring>…
题目链接. 分析: 感叹算法的力量. 方法一: 设 dp[i][j] 为字符串 s, 从 i 到 j 需要添加的最少字符数. 那么如果 s[i] == s[j], dp[i][j] = dp[i+1][j-1]. 如果 s[i] != s[j], dp[i][j] = min(dp[i+1][j], dp[i][j-1]) + 1. #include <iostream> #include <cstdio> #include <cstdlib> #include <…
地址:http://poj.org/problem?id=1159 题目需求: 给你一个字符串,求最少添加多少字符可以使之构成回文串. 题目解析: 简单做法是直接对它和它的逆序串求最长公共子序列长度len.n-len即为所求.(n为原串长度) 即 : 最少补充的字母数 = 原序列的长度 —  原串和逆序的最长公共子串长度 ,  如果最长公共子串长度==原序列长度,则是回文,反之须补充的数目为n-lcs: 这样做的原因如下: 要求最少添加几个字符,我们可以先从原串中找到一个最长回文串,然后对于原串…
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Journey poj1724 - ROADS(邻接表+DFS) BFS poj3278 - Catch That Cow(空间BFS) poj2251 - Dungeon Master(空间BFS) poj3414 - Pots poj1915 - Knight Moves poj3126 - Prim…