演算法›Ch3 動態規劃
第 31 題/共 40 題
◀ AL 31/40
31. Dynamic Programming、String Shuffle、Pseudocode 填空
#AL-03-031中Dynamic ProgrammingString ShufflePseudocode 填空

(10%) Given three strings x[0,...,n−1]x[0, ..., n-1], y[0,...,m−1]y[0, ..., m-1] and z[0,...,r−1]z[0, ..., r-1]. We say that zz is a shuffle of xx and yy if it contains all characters of xx and yy and the left-to-right ordering of the characters from xx and the characters from yy is preserved. For example, "NcCKsiUe" is a shuffle of "NCKU" and "csie". The dynamic programming algorithm uses a table SS to check xx, yy and zz, where S[i][j]S[i][j] is true if and only if the first i+ji+j characters of zz are a shuffle of the first ii characters of xx together with the first jj characters of yy. Complete the following pseudocode for checks whether zz is a shuffle of xx and yy by filling (1), (2) and (3). (please use C-style expression)

isShuffle(x, y, z)
    Let S[0...n][0...m] be a new table
    S[0][0] = true
    if r != n + m
        return false
    for i = 1 to n
        S[i][0] = ____(1) (3%)____
    for j = 1 to m
        S[0][j] = ____(2) (3%)____
    for i = 1 to n
        for j = 1 to m
            S[i][j] = ____(3) (4%)____
    return S[n][m]
📄 成大110
跳轉到第題
▤完整推導請見《WH 資工筆記 · 演算法》Ch3 動態規劃
本章題號 · 21–40 / 40