1
1
/**
2
- * Solution to Magical Cows (https://open.kattis.com/problems/magicalcows)
3
- * Problem author: Graeme Zinck
4
- * Solution by: William Fiset
2
+ * Solution to Magical Cows (https://open.kattis.com/problems/magicalcows) Problem author: Graeme
3
+ * Zinck Solution by: William Fiset
5
4
*
6
- * The main thing to realize with magical cows is that the total number of cows
7
- * allowed on each farm is bounded by C which is less than or equal to 1000, so
8
- * you can keep track of all cows in a frequency table for each farm size.
9
- *
10
- * NOTE: You can ignore taking the floor/ceiling of the number of cows on a
11
- * split since when you double the number of cows you always get an even number.
5
+ * <p> The main thing to realize with magical cows is that the total number of cows allowed on each
6
+ * farm is bounded by C which is less than or equal to 1000, so you can keep track of all cows in a
7
+ * frequency table for each farm size.
8
+ *
9
+ * <p> NOTE: You can ignore taking the floor/ceiling of the number of cows on a split since when you
10
+ * double the number of cows you always get an even number.
12
11
*/
13
-
14
12
import java .io .*;
15
13
import java .util .*;
16
14
@@ -33,8 +31,8 @@ public static void main(String[] args) throws IOException {
33
31
// The number of queries
34
32
final int M = Integer .parseInt (line [2 ]);
35
33
36
- // The dp table.
37
- long [][] dp = new long [MAX_DAYS + 1 ][C + 1 ];
34
+ // The dp table.
35
+ long [][] dp = new long [MAX_DAYS + 1 ][C + 1 ];
38
36
39
37
// Count the initial frequency of farms of different sizes
40
38
for (int i = 0 ; i < N ; i ++) {
@@ -47,11 +45,11 @@ public static void main(String[] args) throws IOException {
47
45
for (int i = 1 ; i <= C ; i ++) {
48
46
if (2 * i <= C ) {
49
47
// Cow count on farm with size `i` doubled, but the number of farms did not.
50
- dp [day ][2 * i ] += dp [day - 1 ][i ];
48
+ dp [day ][2 * i ] += dp [day - 1 ][i ];
51
49
} else {
52
50
// The number of cows per farm on the farm with size `i` exceeds the
53
51
// permitted limit, so double the number of farms.
54
- dp [day ][i ] += 2 * dp [day - 1 ][i ];
52
+ dp [day ][i ] += 2 * dp [day - 1 ][i ];
55
53
}
56
54
}
57
55
}
@@ -73,7 +71,4 @@ private static long query(long[][] dp, int day) {
73
71
}
74
72
return farms ;
75
73
}
76
-
77
74
}
78
-
79
-
0 commit comments