Longest Common Substring

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

요약
길이가 n과 m인 이진 문자열 쌍 중에서 최장 공통 부분 문자열이 길이 3 이하의 주어진 w인 쌍의 개수를 센다.
난이도

어려움10점 중 8점

유형
동적 계획법, 조합론, 문자열
정답자
아직 제출이 없습니다

문제

Lisa wrote a program to solve the Longest Common Substring problem. She then used the program to find, for some two strings ss and tt consisting of characters '0' and '1', the longest string ww that is a substring of both ss and tt. If there were multiple such longest strings, she found an arbitrary one.

Notably, the length of ww Lisa found was very small --- at most 3.

Lisa remembers nn (the length of ss), mm (the length of tt), and ww, but she doesn't remember strings ss and tt themselves. Now she wonders how many pairs of strings ss and tt exist such that they have lengths nn and mm, respectively, consist of characters '0' and '1', and have ww as one of their longest common substrings.

Help Lisa and find this number of pairs modulo 998,244,353998\\,244\\,353. Note that if n=mn = m and s≠ts \ne t, pairs (s,t)(s, t) and (t,s)(t, s) are considered distinct.

입력

The first line contains three integers nn, mm, and kk, denoting the lengths of the strings ss, tt, and ww (1≤n,m≤1001 \le n, m \le 100; 1≤k≤min⁡(3,n,m)1 \le k \le \min(3, n, m)).

The second line contains the string ww of length kk consisting of characters '0' and '1'.

출력

Print the number of pairs of strings (s,t)(s, t) that have ww as one of their longest common substrings, modulo 998,244,353998\\,244\\,353.

힌트

Note that a string aa is a substring of a string bb if aa can be obtained from bb by deleting zero or more characters from the beginning and zero or more characters from the end.

In the first test, all pairs of strings satisfying the conditions are ("01", "10"), ("01", "11"), ("10", "01"), ("10", "11"), ("11", "01"), and ("11", "10").

예제4

  1. 예제 1

    입력
    2 2 1
    1
    
    예상 출력
    6
    
  2. 예제 2

    입력
    3 4 2
    01
    
    예상 출력
    28
    
  3. 예제 3

    입력
    7 5 3
    110
    
    예상 출력
    399
    
  4. 예제 4

    입력
    23 42 3
    000
    
    예상 출력
    174497840