length `length` and 'K factor' = `k_factor` which belong to the criteria represented by that index: - dp[length][k_factor][0] can be the number of strings of length `length` and K-factor = `k_factor` which end with substring 'a' - dp[length][k_factor][1] can be the number of strings of length `length` and K-factor = `k_factor` which end with substring 'ab' - dp[length][k_factor][2] can be the number of strings of length `length` and K-factor = `k_factor` which end with subs
Code!!!!!!'
The K factor of a string is defined as the number of times 'abba' appears as a
substring. Given two numbers `length` and `k_factor`, find the number of
strings of length `length` with 'K factor' = `k_factor`.
The
dp[length][k_factor] will be a 4 element array, wherein each element can be the
number of strings of length `length` and 'K factor' = `k_factor` which belong
to the criteria represented by that index:
- dp[length][k_factor][0] can be the number of strings of length `length`
and K-factor = `k_factor` which end with substring 'a'
- dp[length][k_factor][1] can be the number of strings of length `length`
and K-factor = `k_factor` which end with substring 'ab'
- dp[length][k_factor][2] can be the number of strings of length `length`
and K-factor = `k_factor` which end with substring 'abb'
- dp[length][k_factor][3] can be the number of strings of `length` and
K-factor = `k_factor` which end with anything other than the above
substrings (anything other than 'a' 'ab' 'abb')
Example inputs
length=4 k_factor=1 no of strings = 1
length=7 k_factor=1 no of strings = 70302
length=10 k_factor=2 no of strings = 74357.
No chatgp.
Step by step
Solved in 3 steps with 1 images