经典的最长公共子序列问题,我刚开始用string敲的,就是为了练练手,没想到竟然wa了,还以为我用错了呢。。。换了字符数还是wa。。。真无语,这么简单的题快把我弄糊涂了,后来听人说是输入可能有空格。。。这是巨坑啊,题上都没说清楚,白白wa了几发。。。就是设一个数组d[i][j]遍历两个字符数组当a[i]==b[j]的时候d[i][j]=d[i-1][j-1]+1。不相等的时候就是d[i][j]=m...
分类:
其他好文 时间:
2015-08-09 17:18:31
阅读次数:
123
http://poj.org/problem?id=1458Common SubsequenceTime Limit:1000MSMemory Limit:10000KTotal Submissions:43077Accepted:17439DescriptionA subsequence of a...
分类:
其他好文 时间:
2015-08-08 09:05:41
阅读次数:
91
题目传送门 1 /* 2 LPS(Longest Palidromic Subsequence):最长回文子序列,和回文串不同,子序列是可以不连续的。 3 转化为LCS问题,将字符串逆序,然后和本串求LCS就是LPS的长度(为啥不就是LPS?),但是前一半是LPS的一半,可以...
分类:
其他好文 时间:
2015-08-07 18:53:21
阅读次数:
190
#include#include#include#include#include#define INF 30000000#define pai 3.1415926using namespace std;char s1[1000],s2[1000];int dp[1000][1000];int mai...
分类:
其他好文 时间:
2015-08-06 22:09:09
阅读次数:
113
问题:Given an array of N integer, find the length of the longest increasing subsequence.For example, given [1,-5,4,5,10,-1,-5,7], the longest increasing...
分类:
编程语言 时间:
2015-08-05 00:40:24
阅读次数:
154
//1 a b 将a位置的数改为b
//0 a b 输出[a,b] 区间内的 maximum sum of beautiful subsequence
//A beautiful subsequence is a subsequence that all the adjacent pairs
//of elves in the sequence have a different parity of...
分类:
其他好文 时间:
2015-08-02 15:13:38
阅读次数:
141
题意简述:求两个字符串的最长公共子序列的长度思路:最经典的最长公共子序列的长度(LCS问题)。动态转移方程如下:字符串X和字符串Y,dp[i][j]表示的是X的前i个字符和Y的前j个字符的最长公共子序列长度。如果 X[i]==Y[j],那么新的LCS+1;如果X[i]!=Y[j],则分别考察dp[i...
分类:
其他好文 时间:
2015-08-02 15:07:12
阅读次数:
80
传送门十分重要的基础DP问题,是学习用各种方式优化DP的一个很好的例子。设DP[i]表示以a[i]结尾的LIS的长度,则状态转移方程为DP[1]=1DP[i] = max{DP[j], j1暴力求解复杂度为O(N^2)。优化1考虑函数f(L):长度为 L 的 Increasing Sequence ...
分类:
其他好文 时间:
2015-08-01 20:28:08
阅读次数:
90
1001. Magician (hdu5316)这个题目用到线段树来合并区间,题目有句话的意思A beautiful subsequence is a subsequence that all the adjacent pairs of elves in the sequence have a di...
分类:
其他好文 时间:
2015-07-30 11:09:28
阅读次数:
114
Thelongest common subsequence(LCS)problemis the problem of finding the longestsubsequencecommon to all sequences in a set of sequences (often just two...
分类:
其他好文 时间:
2015-07-30 07:10:57
阅读次数:
120