Skip to content

Commit fb172f0

Browse files
William FisetWilliam Fiset
William Fiset
authored and
William Fiset
committed
MagicalCows slides + formattin
1 parent 3eea6a0 commit fb172f0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed
Binary file not shown.

src/main/java/com/williamfiset/algorithms/dp/examples/magicalcows/MagicalCows.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public static void main(String[] args) throws IOException {
4343
dp[0][cows]++;
4444
}
4545

46-
for (int day = 1; day <= MAX_DAYS; day++) {
46+
for (int day = 0; day < MAX_DAYS; day++) {
4747
// For all farm sizes between 1 and `C`, double the number of cows.
4848
for (int i = 1; i <= C; i++) {
49-
if (2 * i <= C) {
49+
if (i <= C / 2) {
5050
// Cow count on farm with size `i` doubled, but the number of farms did not.
51-
dp[day][2 * i] += dp[day - 1][i];
51+
dp[day + 1][i * 2] += dp[day][i];
5252
} else {
5353
// The number of cows per farm on the farm with size `i` exceeds the
5454
// permitted limit, so double the number of farms.
55-
dp[day][i] += 2 * dp[day - 1][i];
55+
dp[day + 1][i] += 2 * dp[day][i];
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)