摘要: 1. 问题描述 给定一个序列 A[ 1 : n ],求其一个子序列 A[ i : j ],使得从 A[ i ] 到 A[ j ] 的和最大。2. 动态规划解用 opt[ i ] 表示以 A[ i ] 为末尾元素的所有连续子序列和的最大者,则opt[ 1 ] = A[ 1 ]当 i > 1 时:如果 opt[ i - 1 ] 0, 则 opt[ i ] = A[ i ] + opt[ i - 1 ]则结果为 max{ opt[1], opt[2], ..., opt[n] }。时间复杂度为 O(n), 空间复杂度为 O(1)。3. 扩展:首尾相连的情形考虑序列 B = [A1, A2, . 阅读全文
posted @ 2013-09-21 20:58 半亩梨花 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 1. 问题描述有一个序列 A = a[1:n], 若存在一个数列bm,其中对于任何1 int LIS(Iter beg, Iter end, Compare op){ if(beg == end) return 0; int n = end - beg; std::vector opt(n); opt[0] = 1; Iter id = std::next(beg); for(int i = 1; i b ? a : b;}); return length_opt;}templateint LIS(Iter beg, Iter end){ ... 阅读全文
posted @ 2013-09-21 07:15 半亩梨花 阅读(249) 评论(0) 推荐(0) 编辑