随笔分类 - 动态规划—区间dp
摘要:ps:枚举翻转区间的端点的数值,因为每个数都在0~9范围内,所以只需要枚举45种情况(C(10,2)组合数)。b串:0 1 2 3 4 5 6 7 8 9,枚举翻转区间的端点的数值3,6,得到新的b串:0 1 2 3 6 5 4 3 6 7 8 9,让这个串与原串跑一遍普通的最长公共子序列就能得到答
阅读全文
摘要:You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each pl
阅读全文
摘要:Feuzem is an unemployed computer scientist who spends his days working at odd-jobs. While on the job he always manages to find algorithmic problems wi
阅读全文
摘要: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
阅读全文
摘要:题意:添加尽量少的字符使得s串成为回文串,并输出这样得解。 题解:dp[ i ][ j ]表示i~j串需要添加的最少字符。 当s[ i ]==s[ j ]时,dp[ i ][ j ]=dp[ i +1 ][ j - 1 ]; 当s[ i ]! =s[ j ]时,dp[ i ][ j ]=min( d
阅读全文
摘要:不明白为啥倒着刷表,顺着应该也行啊。 打印要用递归的思想,正是我的痛点啊。 注意输入串可能是空串,不能用scanf。。
阅读全文
摘要:题解:dp[ i ][ j ]=min { dp[ i ][ k ]+dp[ k ][ j ] }+a[ j ]-a [i ]。 和石子归并是一样的问题,枚举区间的长度,然后更新这个区间的值。
阅读全文
摘要:Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Hal
阅读全文
摘要:If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be Input The first line of the input contains the number o
阅读全文
摘要:N堆石子摆成一条线。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的代价。计算将N堆石子合并成一堆的最小代价。 例如: 1 2 3 4,有不少合并方法 1 2 3 4 => 3 3 4(3) => 6 4(9) => 10(19) 1 2 3
阅读全文
![](https://images.cnblogs.com/cnblogs_com/zgglj-com/1682556/o_200327152908zg.jpg)