Skip to content

Commit ad48b46

Browse files
cats explanation
1 parent fde3832 commit ad48b46

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

BkOI/Balkan 17-Cats.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
DP: dp[i][j][k][l] = minimum swaps to...
3+
- ensure that all the animals from [0...i) are arranged properly
4+
- the current section is of type j (ie. the next animal must be of type j or be a lion)
5+
- if k is 0, then we have only had one type of animal. If k is 1, then we have had both types of animals.
6+
k needs to be 1 at the end of our DP -- otherwise one type of animal will have nowhere to go.
7+
- we have l lions that can be moved arbitrarily
8+
9+
Transition: For the animal A[i]...
10+
- If A[i] is of type x, then if j = x, we can transition to dp[i+1][j][k][l] with no additional cost.
11+
- Otherwise, we can either add one to move A[i] to a different location, or we can add one and move a lion
12+
between A[i] and A[i-1]. This changes our j value as well.
13+
- If A[i] is a lion, we can either:
14+
- Do nothing
15+
- Or, decrement l and change j. We can do this for free since the lion is already in the right position
16+
to change the current type of animal.
17+
*/
18+
119
#include <bits/stdc++.h>
220

321
using namespace std;

0 commit comments

Comments
 (0)