"Dynamic planning" xmu 1030 distressed Matchmaker

Source: Internet
Author: User
Tags cas first string

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.