Introduction to Algorithms (DP IV: Guitar Fingering, Tetris, Super Mario Bros)

Piano/Guitar Fingering

  • given musical piece to play, say sequence of n (single) notes with right hand
  • fingers 1, 2, . . . , F = 5 for humans
  • metric d(f, p, g, q) of difficulty going from note p with finger f to note q with finger g

Correct DP:

  1. subproblem = min difficulty for suffix notes[i :] given finger f on first note[i]
  2. guessing = finger g for next note[i + 1]
  3. recurrence:
    1. DP[i, f] = min(DP[i + 1, g] + d(note[i], f, note[i + 1], g) for g in range(F))
    2. DP[n, f] = 0
  4. topo. order: for i in reversed(range(n)): for f in 1, 2, . . . , F: total time O(nF^2 )
  5. orig. prob. = min(DP[0, f] for f in 1, . . . , F)

猜你喜欢

转载自blog.csdn.net/Da_tianye/article/details/81368881