Topic Links:
http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1030
Main Topic :
For the length and contents of a given two string, the longest common subsequence is obtained.
Topic Ideas:
"Dynamic Planning"
To find the longest common child sequence. F[I][J] represents the first string to match to I, and the second string matches the maximum length of J.
1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> - //#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineLowbit (a) (a& (a)) + #defineSqr (a) ((a) * (a)) - #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b)) + #defineEPS (1E-8) A #defineJ 10000000 at #defineMAX 0x7f7f7f7f - #definePI 3.1415926535897 - #defineN 1004 - using namespacestd; -typedefLong LongLL; - intCas,cass; in intN,m,lll,ans; - CharA[n],b[n]; to intF[n][n]; + intMain () - { the #ifndef Online_judge * //freopen ("1.txt", "R", stdin); $ //freopen ("2.txt", "w", stdout);Panax Notoginseng #endif - inti,j,l; the //for (scanf ("%d", &cas); cas;cas--) + //for (scanf ("%d", &cas), cass=1;cass<=cas;cass++) A //while (~scanf ("%s", s)) the while(~SCANF ("%d",&N)) + { -scanf"%d",&m); $scanf"%s%s", A +1, B +1); $ for(i=1; i<=n;i++) - { - for(j=1; j<=m;j++) the { -F[i][j]=max (f[i-1][j],f[i][j-1]);Wuyi if(A[i]==b[j]) F[i][j]=max (f[i][j],f[i-1][j-1]+1); the } - } Wuprintf"%d\n", F[n][m]); - } About return 0; $ } - /* - // - A // + */
don't do it.
"Dynamic planning" xmu 1030 distressed Matchmaker