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

×

# NOSTRING - Editorial

Author: Varun Singh

EASY-MEDIUM

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 63
accept rate: 0%

 toggle preview community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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