LeetCode 651:四字键盘
题干:假设有一个键盘只有四个键,
A 显示一个A
Ctrl+A 全选
Ctrl+C 复制
Ctrl+V 黏贴
class Solution:
def maxA(self, N):
dp = [0 for i in range(N+1)]
for i in range(1,N+1):
#按A键
dp[i] = dp[i - 1] +1
for j in range(2,i):
#ctrl+A & Ctrl+C dp[j-2] 连续黏贴i-j次,得到dp[j-2]*[i-j+1]个A
dp[i] = max(dp[i], dp[j-2]*(i-j+1))
return dp[N]