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

×

NOSTRING - Editorial

PROBLEM LINK:

Practice Contest

Author: Varun Singh

DIFFICULTY:

EASY-MEDIUM

PREREQUISITES:

DP

PROBLEM:

Given a string s, find all distinct strings of length 2 or 3, which can be suffixes of this word according to the rules given.

EXPLANATION:

The problem is solved with dynamic programming. We can select an arbitrary root of any length (at least 5). Let's reverse the string. A boolean value $dp_{2,3}[n]$ denotes if we could split a prefix of length n to strings of length 2 and 3 so that the last string has a corresponding length. Transitions: $dp_2[n] = dp_3[n-2] ∨ (dp_2[n-2] ∧ s[n-3;n-2] ≠ s[n-1;n])$. Similarly, $dp_3[n] = dp_2[n-3] ∨ (dp_3[n-3] ∧ s[n-5;n-3] ≠ s[n-2;n])$. If any of $dp_k[n]$ is true we add the corresponding string to the set of answers.

AUTHOR'S SOLUTIONS:

Author's solution can be found here.

This question is marked "community wiki".

asked 01 Apr '17, 17:37

varuns_2729's gravatar image

4★varuns_2729
63
accept rate: 0%

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:

×2,214
×1,723
×354
×38

question asked: 01 Apr '17, 17:37

question was seen: 582 times

last updated: 01 Apr '17, 17:37