-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e243a6a
commit 07c20b2
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
02_Dynamic-Programming/12. DP Using 1D Array/27. 4 Keys Keyboard.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# https://www.lintcode.com/problem/867 | ||
|
||
class Solution: | ||
def max_a(self, n: int) -> int: | ||
dp = [i for i in range(n+1)] | ||
for i in range(4, n+1): | ||
count = 2 | ||
prev = i-3 | ||
while prev > 0: | ||
dp[i] = max(dp[i], count*dp[prev]) | ||
prev -= 1 | ||
count += 1 | ||
return dp[n] | ||
|
||
|
||
# Time: O(N^2) | ||
# Space: O(N) |