AC Diary--Character token Openjudge 1.7 30

Source: Internet
Author: User

30: Character Token
Total time limit:
1000ms
Memory Limit:
65536kB
Describe

There are two rings composed of characters. Please write a program that calculates the length of the longest contiguous public string on the token of the two characters. For example, the strings "ABCEFAGADEGKABUVKLM" are joined together to form a ring; the string "Madjkluvkl" is joined together to form a second ring; "Uvklma" is a contiguous public string of these two rings.

Input
A row that contains two strings that correspond to one character token. The two strings are separated by a single space. The string length does not exceed 255, and it does not contain whitespace such as spaces.
Output
Outputs an integer that represents the length of the longest public string on the token of the two words.
Sample input
ABCEFAGADEGKABUVKLM MADJKLUVKL
Sample output
6

Ideas:

Dynamic return;

Come on, on the code:

#include <cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;intlen_1,len_2,ans,cur_ans=0, dp[520][520];BOOLci[520][520];stringword_1,word_2;intMain () {CIN>>word_1>>word_2; Len_1=word_1.length (), len_2=word_2.length (); Ans=min (len_1,len_2); //for (int i=0;i<len_1;i++) word_1[i+len_1]=word_1[i]; //for (int i=0;i<len_2;i++) word_2[i+len_2]=word_2[i];word_1+=word_1,word_2+=word_2; Len_2*=2, len_1*=2;  for(intI=0; i<len_1;i++)    {         for(intj=0; j<=len_2;j++)        {            if(Word_1[i]==word_2[j]) ci[i+1][j+1]=true, dp[i+1][j+1]++; }    }     for(intI=1; i<=len_1;i++)    {         for(intj=1; j<=len_2;j++)        {            if(Ci[i][j]) {if(ci[i-1][j-1]) Dp[i][j]=max (dp[i][j],dp[i-1][j-1]+1); Cur_ans=Max (cur_ans,dp[i][j]); }}} ans=min (Ans,cur_ans); printf ("%d\n", ans); return 0;}

AC Diary--Character token Openjudge 1.7 30

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.