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
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Manthan 2010 » Edit Distance

Edit Distance

Problem code: CF02

  • All Submissions

All submissions for this problem are available.

Run-length encoding(RLE) is a very simple and easy form of data compression in which consecutive occurrences of the same characters are replaced by a single character followed by its frequency. As an example, the string S aabbbbdaa would be encoded to a2b4d1a2.

Thus encoded string is described as an ordered sequence of pairs (a, i), each consisting of an alphabet symbol a and an integer i. Each pair corresponds to a run in S consisting of i consecutive occurrences of a.

In this problem, we are interested in finding the minimum number of mutation(s) needed to transform first string given in encoded form into second string i.e. edit distance when only two operation are allowed

  1. Add any character at any position(insertion)
  2. Remove any character from any position(deletion)

The cost of inserting a character is 1 and cost of deleting a character is 2.

Input

The input file contains several test cases. The first line of the input denotes the number of test cases, T (1 T 100) to follow. Each test case begins on a new line and consists of an integer L1, a blankspace and a run length encoded string S1 and then on a new line, an integer L2, a blankspace and a run length encoded string S2.

L1 and L2 denote the number of runs in strings S1 and S2 respectively. 1<=L1,L2<=100.
S1 and S2 consists of alphabets [a-z] followed by number of consecutive occurrences of that character.

You can safely assume that the total length of any of the strings will not exceed 3000 characters.

Output

For each test case, output the edit distance from S1 to S2 in a new line.

Example

Input:
2
2 a3b2
1 b3
3 a1b1a1
1 a2
Output:
7
2


Author: manthan
Date Added: 26-03-2010
Time Limit: 2 sec
Source Limit: 50000 Bytes
Languages: C, CLOJ, CPP 4.0.0-8, CPP 4.3.2, F#, GO, PERL6, PYTH 3.1.2, TEXT


  • Submit

Comments

  • Login or Register to post a comment.

"You can safely assume that

cro1 @ 28 Mar 2010 06:22 PM

"You can safely assume that the total length of any of the strings will not exceed 3000 characters."

Is this sentence about the original string, or the encoded string?

Will there be input like c6c6

screw_it @ 28 Mar 2010 06:26 PM

Will there be input like c6c6 ?

The length constraint is

manthan @ 28 Mar 2010 06:27 PM
The length constraint is corresponding to original string. For e.g. if the encoded string is a3b2, the string length is 5 characters.

No. There is no such input in

manthan @ 28 Mar 2010 06:29 PM
No. There is no such input in the judge test cases. c6c6 will be c12.

What is the maximum length of

screw_it @ 28 Mar 2010 07:00 PM

What is the maximum length of a run, for e.g. if input is of form aX
what is maximum value of integer X?

@screw_it: As the original

manthan @ 28 Mar 2010 07:05 PM

@screw_it: As the original string (not the encoded string) can be of maximum 3000 characters, X can maximum be 3000, if number of run is 1

Is the second test case right

Villain @ 28 Mar 2010 07:08 PM

Is the second test case right ???

Yes, by deleting the 'b'

Thelhoers @ 28 Mar 2010 07:12 PM

Yes, by deleting the 'b'

is the run length positive?

cro1 @ 28 Mar 2010 07:42 PM

is the run length positive?

@Musketiri: Yes run lengths

manthan @ 28 Mar 2010 07:45 PM

@Musketiri: Yes run lengths are always positive (>0).

Is it possible to submit

Coodle @ 28 Mar 2010 08:03 PM

Is it possible to submit solution in JAVA

Current ranking is available

manthan @ 28 Mar 2010 08:08 PM

Current ranking is available at http://www.codechef.com/teams/list/MANTH10/

@sam6230i: No only C/CPP

manthan @ 28 Mar 2010 08:12 PM

@sam6230i: No only C/CPP codes are allowed for the contest.

Hi, can we know why our team

team_khan @ 28 Mar 2010 09:00 PM

Hi, can we know why our team is not elligible, I have registered our team at the CodeFest website before the start of contest and also my current team ID is our team name at your website.

 

Thanks

@ThreeKhan : Eligible team

manthan @ 28 Mar 2010 09:24 PM

@ThreeKhan : Eligible team section shows invalid data. All teams registered on Codechef wenbsite and listed at http://www.codechef.com/teams/list/MANTH10/ are eligible for prizes if they form a team for Manthan at Codefest website with same team members. The team names can be different.

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 algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm 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 programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were 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 challenges 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 coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

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. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

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