CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February Long Contest
    • January CookOff
    • January Long Contest
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
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

oldmonk @ 1 Nov 2009 03:07 PM

@ 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..

triplem @ 1 Nov 2009 03:13 PM

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

Sorry about the confusion.

oldmonk @ 1 Nov 2009 04:51 PM

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

I guess the empty string is

flying_ant @ 1 Nov 2009 10:47 PM

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

@Anil Kishore: When the

chini_1010 @ 2 Nov 2009 12:03 AM
@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

flying_ant @ 2 Nov 2009 12:44 PM

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

freakstone @ 2 Nov 2009 12:50 PM

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.

pathaksandeep @ 2 Nov 2009 02:21 PM

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

admin @ 2 Nov 2009 02:27 PM

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

@Admin I think Kunal's

rohil @ 3 Nov 2009 02:06 AM

@Admin

I think Kunal's question is valid.

Can you please clarify that ?

 

The null string has length 0,

triplem @ 3 Nov 2009 02:09 AM

The null string has length 0, not 1.

@Stephen Yeah, thanks.

rohil @ 3 Nov 2009 02:15 AM

@Stephen

Yeah, thanks. Realized that.

Please don't give away hints

triplem @ 3 Nov 2009 09:24 AM

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

jcomeau_ictx @ 3 Nov 2009 09:33 AM

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

yashwa7 @ 4 Nov 2009 08:46 AM

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

yashwa7 @ 4 Nov 2009 08:51 AM

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

vish @ 4 Nov 2009 01:25 PM

can some one give a good input for this distinct LCS

Sure, after the contest

triplem @ 4 Nov 2009 01:35 PM

Sure, after the contest finishes ;)

@Yashwant We will try to

admin @ 4 Nov 2009 03:00 PM

@Yashwant We will try to introduce this feature.

@admin although i have

gourav roy @ 5 Nov 2009 10:10 AM

@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

admin @ 5 Nov 2009 03:53 PM

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

this is third problem where I

arjundevane @ 6 Nov 2009 09:12 AM

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

vexorian @ 6 Nov 2009 06:10 PM
They just use their evil super powers.

@admin Can you give some test

drain_bamage @ 7 Nov 2009 12:25 AM

@admin

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

what should be the answer in

rocky_racoon @ 7 Nov 2009 06:51 PM

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

rocky_racoon @ 7 Nov 2009 06:55 PM

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

How can the result be mor

sesha_giri_nit @ 8 Nov 2009 12:54 PM

How can the result be mor than 23102009

if the string len is not more than 1000.

@Giri u have to the no. of

rocky_racoon @ 8 Nov 2009 12:55 PM

@Giri

u have to the no. of distinct LCSs

@giri u have to find the

rocky_racoon @ 8 Nov 2009 12:55 PM

@giri

u have to find the distinct LCSs

@ravin   I got that thing but

sesha_giri_nit @ 9 Nov 2009 02:53 PM

@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

triplem @ 11 Nov 2009 04:44 PM

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

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com