String Discrimination
InterviewTime limit2sMemory limit512 MB
Given a target string S and up to 100 words, decide whether S is a concatenation of words from the list, each reusable any number of times.
- Level
Medium4 of 10
- Topics
- Dynamic programming, String, Hash map
- Solved
- No attempts yet
Problem
A string consisting of lowercase alphabet letters and a list of words are given. Write a program that determines whether can be formed by concatenating one or more strings from without any spaces. A word in may be used multiple times.
Input
The first line gives a string whose length is at most 100. The second line gives the number of strings in , (). The following lines give the words in , one per line. Each string in consists only of lowercase alphabet letters and its length does not exceed 100.
Output
Output 1 if can be formed from strings in , and 0 otherwise.