Power String Matching

시간 제한3초메모리 제한2048 MB

요약
s를 연속한 조각으로 나눈 뒤 각 조각을 0회 이상 반복해 이어 붙여 t를 만들 수 있는지 판정한다.
난이도

보통10점 중 7점

유형
동적 계획법, 문자열, 그리디
정답자
아직 제출이 없습니다

문제

For two strings s_1s\_1 and s_2s\_2, let s_1+s_2s\_1+s\_2 denote their concatenation, e.g. abc + cda is the string abccda.

Now for a string ss and an integer k≥0k≥0 we let sks^k denote the result of concatenating kk copies of ss, i.e. ab3=^3=ababab. If k=0k=0, then sks^k is just the empty string.

Finally, a collection of nonempty strings s_1,…,s_ks\_1,\dots ,s\_k is said to partition a string ss if s=s_1+s_2+⋯+s_ks=s\_1+s\_2+\dots +s\_k.

For this problem, you will be given two strings ss, tt. The goal is to determine if there is a partition s_1,s_2,…,s_ks\_1,s\_2,\dots ,s\_k of ss and integers a_1,a_2,…,a_k≥0a\_1,a\_2,\dots ,a\_k≥0 such that t=s_1a_1+s_2a_2+⋯+s_ka_kt=s\_1^{a\_1}+s\_2^{a\_2}+\dots +s\_k^{a\_k}.

입력

The first line of input contains two integers NN (1≤N≤3001≤N≤300) and MM (1≤M≤3001≤M≤300). The second line contains a string ss of length NN and the third line contains a string tt of length MM. Both strings contain only the characters 0 and 1.

출력

Output yes if it there is a partition s_1,s_2,…,s_ks\_1,s\_2,\dots ,s\_k of ss and integers a_1,a_2,…,a_k≥0a\_1,a\_2,\dots ,a\_k≥0 such that t=s_1a_1+s_2a_2+⋯+s_ka_kt=s\_1^{a\_1}+s\_2^{a\_2}+\dots +s\_k^{a\_k}, otherwise output no.

예제3

  1. 예제 1

    입력
    4 5
    1100
    11010
    
    예상 출력
    yes
    
  2. 예제 2

    입력
    4 2
    1100
    01
    
    예상 출력
    no
    
  3. 예제 3

    입력
    9 14
    010100110
    11110101010100
    
    예상 출력
    yes