Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 7, 2024
1 parent cc37223 commit 4b49ed4
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions solutions/gold/usaco-694.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,35 +180,36 @@ dp = [[[0] * 3 for _ in range(25)] for _ in range(MX)]
A = [0] * MX

with open("hps.in") as read:
n, k = map(int, read.readline().strip().split())
n, k = map(int, read.readline().strip().split())

for i in range(n):
a = read.readline().strip()
if a == 'H':
A[i] = 0
elif a == 'P':
A[i] = 1
else:
A[i] = 2
for i in range(n):
a = read.readline().strip()
if a == "H":
A[i] = 0
elif a == "P":
A[i] = 1
else:
A[i] = 2

# either she switches to h or p or s or stays
for i in range(n):
for j in range(k + 1):
for l in range(3):
if l == A[i]:
dp[i][j][l] += 1

dp[i + 1][j + 1][0] = max(dp[i + 1][j + 1][0],
dp[i][j][l]); # switch to not item
dp[i + 1][j + 1][1] = max(dp[i + 1][j + 1][1],
dp[i][j][l]); # switch to not item
dp[i + 1][j + 1][2] = max(dp[i + 1][j + 1][2],
dp[i][j][l]); # switch to not item
dp[i + 1][j][l] = max(dp[i + 1][j][l], dp[i][j][l]); # stay
for j in range(k + 1):
for l in range(3):
if l == A[i]:
dp[i][j][l] += 1

dp[i + 1][j + 1][0] = max(dp[i + 1][j + 1][0], dp[i][j][l])
# switch to not item
dp[i + 1][j + 1][1] = max(dp[i + 1][j + 1][1], dp[i][j][l])
# switch to not item
dp[i + 1][j + 1][2] = max(dp[i + 1][j + 1][2], dp[i][j][l])
# switch to not item
dp[i + 1][j][l] = max(dp[i + 1][j][l], dp[i][j][l])
# stay

res = 0
for i in range(3):
res = max(res, dp[n - 1][k][i])
res = max(res, dp[n - 1][k][i])

print(res, file=open("hps.out", "w"))
```
Expand Down

0 comments on commit 4b49ed4

Please sign in to comment.