feat: added alternative python solutions.
This commit is contained in:
27
vacations/src/alternative-ac.py
Normal file
27
vacations/src/alternative-ac.py
Normal file
@@ -0,0 +1,27 @@
|
||||
n = int(input())
|
||||
days = list(map(int, input().split()))
|
||||
|
||||
INF = float('inf')
|
||||
dp = [[INF] * 3 for _ in range(n)]
|
||||
|
||||
has_competition = lambda a: a & 1
|
||||
has_gym = lambda a: a & 2
|
||||
|
||||
dp[0][0] = 1
|
||||
|
||||
if has_competition(days[0]):
|
||||
dp[0][1] = 0
|
||||
|
||||
if has_gym(days[0]):
|
||||
dp[0][2] = 0
|
||||
|
||||
for i in range(1, n):
|
||||
dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1
|
||||
|
||||
if has_competition(days[i]):
|
||||
dp[i][1] = min(dp[i-1][0], dp[i-1][2])
|
||||
|
||||
if has_gym(days[i]):
|
||||
dp[i][2] = min(dp[i-1][0], dp[i-1][1])
|
||||
|
||||
print(min(dp[n-1]))
|
||||
Reference in New Issue
Block a user