Ultraviolet A 10066 lcs water question
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define INF 100000000 using namespace std; int a [1005]; int B [1005]; int dp [1005] [1005]; int main () {int n, m; int k = 1; while (cin> n> m, n | m) {for (int I = 0; I
Luogu P1439 Longest Common subsequence (LCS problem), p1439lcsDescription
Give two 1-n arrays P1 and P2, and find their longest common subsequences.Input/Output Format
Input Format:
The first row is a number n,
In the next two rows, the number of n rows is an arrangement of 1-n natural numbers.
Output Format:
A number, that is, the length of the longest common subsequence
Input and Output sample input sample #1: Copy
5 3 2 1 4 51 2 3 4 5Output exam
Title Link: http://poj.org/problem?id=2192Problem Solving Report:1. Similar to the longest common subsequence, dp[i][j] Indicates whether a part of the target word is made up of the S1 before I and S2 J characters, is successful2. State Transfer equation:if (i>0s3[i+j-1]==s1[i-1]dp[i-1][j]) Dp[i][j] =1; if (j>0s3[i+j-1]==s2[j-1]dp[i][j-1]) Dp[i][j]=1;/* #include */#include#includestring.h>#includeusing namespacestd;intMain () {intCase=1; intT; scanf ("%d",t); while(t--) { Char
This problem, the boundary processing is more complex, I summed up the discussion, and finally WA, hey, read the Dicuss code, processing or clever#include #include#include#include#includestring>#includeusing namespacestd;Const intMAXN = 1e3+Ten;intDP[MAXN][MAXN];intMain () {strings1,s2; while(cin>>s1>>S2) {memset (DP,0,sizeof(DP)); intN1 =s1.length (); intN2 =s2.length (); for(intI=1; i){ for(intj=1; j){ if(s1[i-1]==s2[j-1]) {Dp[i][j]= dp[i-1][j-1]+1; }Else{Dp[i][j]=
1. LISO (n^2):/*lis (longest increasing subsequence) longest ascending subsequence O (n ^ 2) state transfer equation: dp[i] = max (Dp[j]) + 1 (a[j] O (NLOGN):/*lis binary search optimization, O (NLOGN) set the current longest increment subsequence as Len, considering element A[i]; If D[len] LIS LCS lcis templates
=i 1;//with the operation when I is odd k=1, when I the even number is K is 0 Amemset (G[k],0,sizeof(G[k])); atmemset (F[k],0,sizeof(F[k])); -g[k][0]=1; -g[!k][0]=1; - for(intj=1; j) - { - if(s1[i-1]==s2[j-1]) in { -f[k][j]=f[!k][j-1]+1; tog[k][j]=g[!k][j-1]; +g[k][j]%=m; - if(f[k][j]==f[!K] [j]) the { *g[k][j]+=g[!K] [j]; $g[k][j]%=m;Panax Notoginseng } - if(f[k][j-1]==F[k][j]) the
DP[I][J] Indicates how many of the same subsequence pairs are in the number of pre-I and B-sequences before the a sequence. Complexity O (n^2)o(n? 2?? )/* by*/#include#include#include#includeusing namespaceStd;typedefLong LongLL;ConstLL n=1010;ConstLL mod=1000000007; LL A[n],b[n]; LL Dp[n][n];intMain () {LL n,m,i,j; while(~SCANF ("%lld%lld",n,m) {memset (DP,0,sizeof(DP)); for(i=1; i) scanf ("%lld",A[i]); for(i=1; i) scanf ("%lld",B[i]); for(i=1; i) { for(j=1; j) {
Topic linksDescriptionGiven two string a B, the longest common subsequence of A and B (the subsequence is not required to be contiguous).For example, two strings: ABCICBA Abdkscab AB is a sub-sequence of two strings, and ABC is also, ABCA, where ABCA is the longest subsequence of the two strings.InputLine 1th: String ALine 2nd: string b(A, B's length OutputOutput the longest sub-sequence, if there are multiple, randomly output 1.Input exampleAbcicbaAbdkscabOutput ExampleABCAThe code is as follow
Test instructions: Given three strings, ask you if the third one is not made up of the first and the second.Analysis: At that time the game did not make Ah ... Always WA, is not judging the length, the first and the second and is not the same as the third one, this forget ...We use D[I][J] to indicate that the first string matches to I, the second match to the J, and then just judge if it can be obtained from the previous one. This is mostly d[i][j]==1, which means that it can be successfully ma
Brief Description:A history exam, there are n historical events, and the years between them are different, and students are asked to arrange them in the correct order. There are two ways to score, using the second: Assuming that there are historical events 1,2,3,4, their correct chronological order is 1,2,3,4, and then assuming the student's answer is 1,3,2,4, then according to the correct number of relative order, answer three (1,2,4 or 1,3,4), That is, the longest common subsequence length wit
Common subsequenceTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 25791 Accepted Submission (s): 11432Problem Descriptiona subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence x = The program input was from a text file. Each data set in the file contains the strings representing the given sequences. The sequences is separated by any number of white spaces. The input data is correc
Common subsequenceTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total submission (s): 24489 Accepted Submission (s): 10823Problem Descriptiona subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence x = The program input was from a text file. Each data set in the file contains the strings representing the given sequences. The sequences is separated by any number of white spaces. The input data is correc
LCS (longest common subsequence) is the problem of finding the longest public substring of two strings.
For example:
String str1 = new string ("adbccadebbca ");String str2 = new string ("edabccadece ");The common substring of str1 and str2 is bccade.
The solution is to use a matrix to record the matching conditions between the two characters at all positions in two strings. If it matches, it is 1; otherwise, it is 0. Then we can find the longest 1 ser
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.