一个字符串,每插入或者删除一个字符都需要一定的代价,问怎样可以使这个字符串变成一个回文串,且花费最小。
区间DP
当DP到区间[i,j+1]时,我们可以在i-1的位置添加一个str[j+1]字符,或者将在j+1处的字符删除,得到一个新的回文串,而且我们这两步操作都没有借助或者影响区间[i,j]的情况。
因此,那我们就可以将添加或者删除整合在一起,对字符str[j+1]的操作就按照...
分类:
其他好文 时间:
2014-07-30 14:50:53
阅读次数:
152
题目大意:
有n个男屌丝事先按1,2,3,,,,,,n的顺序排好,每个人都有一个不开心值unhappy[i],如果第i个人第k个上台找对象,那么该屌丝男的不开心值就会为(k-1)*unhappy[i],因为在他前面有k-1个人嘛,导演为了让所有男屌的总不开心值最小,搞了一个小黑屋,可以通过小黑屋来改变男屌的出场顺序
注意:这个小黑屋是个栈,男屌的顺序是排好了的,但是可以通过入栈出栈来改变男屌的...
分类:
其他好文 时间:
2014-07-22 22:39:14
阅读次数:
264
题目大意:给定一个字符串,求最少插入几个字符让该字符串成为回文串
法一:
dp[i][j]表示使区间[i,j]成为回文串最小插入的字符数,则状态转移方程
1、if s[i]==s[len-1] 则:d[i][j]=d[i+1][j-1]
2、else d[i]=min(dp[i+1][j],dp[i][j-1])
首尾字符不同的时候,有两种决策。
1、将新字符插在首位,那么状态就...
分类:
其他好文 时间:
2014-07-21 23:30:01
阅读次数:
255
怒拿一血,first blood,第一个区间DP,第一次就这样子莫名其妙不知不觉滴没了~~~
题目虽然是鸟语,但还是很赤裸裸的告诉我们要求最大的括号匹配数,DP走起~
dp[i][j]表示区间[i,j]的最大匹配数,那么最重要的状态转移方程就是:
dp[i][j]=max(dp[i][k]+dp[k+1][j])
对啦,要先初始化边界啊,两步走~:
memset(dp,0,siz...
分类:
其他好文 时间:
2014-07-21 23:27:29
阅读次数:
214
Problem Description
The TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small hall...
分类:
其他好文 时间:
2014-07-21 22:36:27
阅读次数:
249
Description
FJ has purchased N (1
The treats are interesting for many reasons:
The treats are numbered 1..N and stored sequentially in single file in a long box that is open at both ends. On...
分类:
其他好文 时间:
2014-07-21 22:18:18
阅读次数:
227
Description
The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points ...
分类:
其他好文 时间:
2014-07-21 22:11:18
阅读次数:
289
题目来源:POJ 2955 Brackets
题意:最大括号匹配
思路:
#include
#include
#include
#include
using namespace std;
const int maxn = 210;
int dp[maxn][maxn];
char a[maxn];
int b[maxn];
int dfs(int l, int r)
{
if(l ...
分类:
其他好文 时间:
2014-07-21 14:07:05
阅读次数:
178
Problem Description
The professors of the Bayerische Mathematiker Verein have their annual party in the local Biergarten. They are sitting at a round table each with his own pint of beer. As a ceremo...
分类:
其他好文 时间:
2014-07-21 11:31:44
阅读次数:
252
Problem Description
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, ...
分类:
其他好文 时间:
2014-07-21 11:13:44
阅读次数:
270