You are not logged in. Please login at www.codechef.com to post your questions!

×

KGP13I - Editorial

1
1

PROBLEM LINK:

Practice
Contest

Editorialist: Jingbo Shang

DIFFICULTY:

Easy - Medium

PREREQUISITES:

Dynamic Programming

PROBLEM:

Given 3 types of operations, determine the minimum cost of transforming string S[1..n] to T[1..m].

EXPLANATION:

This problem is similar to the Edit Distance Problem. But here, due to the different cost plan, we need to slightly modify the classical dynamic programming.

Let's use f[i][j] to stand for the minimum cost of transform S[1..i] to T[1..j]. In this problem, the insert/delete cost is dependent on the length.

Consider the insert operation:

f[i][j - k] + min{k + x, y} --update--> f[i][j]

And the delete operation:

f[i - k][j] + k + x --update--> f[i][j]

Replace/Directly match

f[i][j] + (S[i + 1] != T[j + 1]) --update--> f[i + 1][j + 1]

Since we need to enumerate "k", the time complexi will be O(n m^2 + n^2 m).

This question is marked "community wiki".

asked 29 Dec '13, 11:30

admin's gravatar image

0★admin ♦♦
19.8k350498541
accept rate: 36%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,678
×2,169
×1,672
×14

question asked: 29 Dec '13, 11:30

question was seen: 1,134 times

last updated: 29 Dec '13, 11:30