LOGIN
  • Register
  • Forgot Password?

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • March Algorithm Challenge
    • February Algorithm Challenge
    • January Algorithm Challenge
    • December Algorithm Challenge
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • About Directi
    • Careers
Home » Compete » November 2009 (Contest X) » The LCS Problem Revisited

The LCS Problem Revisited

Problem code: J2

  • All Submissions

All submissions for this problem are available.

The Longest Common Subsequence (LCS) problem is a well known problem in Computer Science. Every computer science students in Byteland knows this problem. Johnny does, too.

Recall that a subsequence of a string S is obtained by deleting some characters from S. Given two strings S and T, the LCS problem is the find the longest sequence that is a subsequence of both S and T.

Johnny has the habit of deriving harder problems from a familiar problem. This time, based on the LCS problem, he has thought up the following problem:

Given two strings S and T, how many distinct LCS of S and T are there?

Write a program to help Johnny solve this problem. Since the result may be very large, you only need to print the remainder of the result when dividing by 23102009.

Input

The first line contains t, the number of test cases (about 10). Then t test cases follow.

Each test case consists of two lines, the first line is the string S and the second line is the string T. You may assume that the strings consists of only lowercase characters and the length of the each string is at most 1000 characters.

Successive test cases at input are separated by a single blank line.

Output

For each test case, print a single line containing two numbers which are the length of the LCS and the remainder of the number of distinct LCS of S and T when dividing by 23102009.

Example

Input
2
acbd
acbd

vnvn
vn

Output
4 1
2 1

Output details

The only LCS in the first case is "acbd" and in the second case is "vn".


Date: 2009-10-15
Time limit: 3.5s
Source limit: 50000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK TEXT JS


  • Submit

Comments

  • Login or Register to post a comment.

@ admins: From what i

Kailash H D - 1st Nov,2009 15:07:50.

@ admins: From what i understand of the problem the second case output should be 2 4 and not 2 1. Could you please check that.

2 1 seems correct to me..

Stephen Merriman - 1st Nov,2009 15:13:56.

2 1 seems correct to me.. there is only one common subsequence of length 2.

Sorry about the confusion.

Kailash H D - 1st Nov,2009 16:51:55.

Sorry about the confusion. Did not read that the LCS should be distinct.

I guess the empty string is

Anil Kishore - 1st Nov,2009 22:47:38.

I guess the empty string is counted as 1 LCS, incase of none.. as in , "abcd" and "efgh"

@Anil Kishore: When the

Srinivas - 2nd Nov,2009 00:03:25.
@Anil Kishore: When the Length of LCS is 0 it implies that the distinct LCS is Empty String hence the Output would be 0 1.

Ya.. but shouldn't it be 0 0

Anil Kishore - 2nd Nov,2009 12:44:47.

Ya.. but shouldn't it be 0 0 , because.. empty string can be a answer always, but even for "abc" , "ade" answer is 0 1

what will be output for

kunal - 2nd Nov,2009 12:50:28.

what will be output for "abcd" and "a"

is it 1 1

or 1 2 /*cosidering null string also*/

Can there be more test cases.

Sandeep Pathak - 2nd Nov,2009 14:21:27.

Can there be more test cases. The test cases given in the problem are just too trivial. I have checked my code against a lot of test cases and seem to be getting the correct answer but everytime I submit the code, codechef says "wrong answer" :(

The example test cases are

Aniruddha (Codechef) - 2nd Nov,2009 14:27:21.

The example test cases are enough for explaining the concept :)

@Admin I think Kunal's

Rohil - 3rd Nov,2009 02:06:38.

@Admin

I think Kunal's question is valid.

Can you please clarify that ?

 

The null string has length 0,

Stephen Merriman - 3rd Nov,2009 02:09:34.

The null string has length 0, not 1.

@Stephen Yeah, thanks.

Rohil - 3rd Nov,2009 02:15:18.

@Stephen

Yeah, thanks. Realized that.

Please don't give away hints

Stephen Merriman - 3rd Nov,2009 09:24:55.

Please don't give away hints or anything that will help others solve the problem, as you are setting yourself up for disqualification. Hopefully the admin can delete these comments before anyone else can see them.

I don't see how this helps

John Comeau - 3rd Nov,2009 09:33:27.

I don't see how this helps anybody solve the problem, but will delete the comments if you tell me how.

Admin, You'd have known by

Yashwant Vijayakumar - 4th Nov,2009 08:46:24.

Admin,

You'd have known by now, but still just wanted to point out. I get the following error when viewing some profiles:

warning: Division by zero in /var/www/html/codechefbeta/codechef/api/all_functions.php on line 43 :)

 

Admin, If an answer is

Yashwant Vijayakumar - 4th Nov,2009 08:51:58.

Admin,

If an answer is correct, I'd like to see the execution time along side the "correct answer" display. I've requested for this already but still find it hasn't been done :(

can some one give a good

soc - 4th Nov,2009 13:25:22.

can some one give a good input for this distinct LCS

Sure, after the contest

Stephen Merriman - 4th Nov,2009 13:35:21.

Sure, after the contest finishes ;)

@Yashwant We will try to

Aniruddha (Codechef) - 4th Nov,2009 15:00:11.

@Yashwant We will try to introduce this feature.

@admin although i have

gourav - 5th Nov,2009 10:10:04.

@admin although i have declared a variable ,on submitting my solution it is giving that the variable is not declared in scope

can you plzz help me out

@gourav We cannot help out in

Aniruddha (Codechef) - 5th Nov,2009 15:53:19.

@gourav We cannot help out in such a way during the contest.

this is third problem where I

Arjun Devane - 6th Nov,2009 09:12:20.

this is third problem where I have designed an algorithm, but was too time consuming. I dont know how you guys get it right so early?? specially this one. just the thought of 1000 char long string's subsequences give me chills.

anyway, now trying totally different approach.

They just use their evil

Victor Hugo Soliz Kuncar - 6th Nov,2009 18:10:38.
They just use their evil super powers.

@admin Can you give some test

Siddharth Singh - 7th Nov,2009 00:25:42.

@admin

Can you give some test cases ? I am getting WA. :(

what should be the answer in

ravin - 7th Nov,2009 18:51:53.

what should be the answer in case of abcd and efgh.is it (0 0 )or (0 1)

i need a single test case to

ravin - 7th Nov,2009 18:55:10.

i need a single test case to check my soln.i am getting WA :(

How can the result be mor

Giri - 8th Nov,2009 12:54:06.

How can the result be mor than 23102009

if the string len is not more than 1000.

@Giri u have to the no. of

ravin - 8th Nov,2009 12:55:06.

@Giri

u have to the no. of distinct LCSs

@giri u have to find the

ravin - 8th Nov,2009 12:55:46.

@giri

u have to find the distinct LCSs

@ravin   I got that thing but

Giri - 9th Nov,2009 14:53:17.

@ravin

 

I got that thing but can you tell give me an example in which the value can be more than the string length.

I am not able to find any such case..

Hope you got what i my confussion is

A tutorial for this problem

Stephen Merriman - 11th Nov,2009 16:44:42.

A tutorial for this problem can be found here: Tutorial for The LCS Problem Revisited

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Fetching successful submissions
  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
Sponsors
The time now is: