Problem Statement
You are planting some crops in a rectangular field, divided into cells, width by height. Any given cell can have at most one crop growing in it. Any square area of length size can only have at most max crops growing in it. What is the most number of crops that can be grown in the field?
Definition
- Class:
- MaxPlanting
- Method:
- most
- Parameters:
- int, int, int, int
- Returns:
- int
- Method signature:
- int most(int width, int height, int size, int max)
- (be sure your method is public)
Constraints
- width will be between 1 and 100, inclusive.
- height will be between 1 and 100, inclusive.
- size will be between 1 and MIN(width, height), inclusive.
- max will be between 1 and 10000, inclusive.
Examples
3
3
2
1
Returns: 4
There are 9 cells in total, but no 2x2 area can have more than one plant. Our best bet is this: X-X --- X-X
3
3
2
2
Returns: 6
Here each 2x2 area can have two crops, so we can do something like this: X-X X-X X-X
10
10
4
5
Returns: 42
3
3
2
3
Returns: 8
3
3
2
5
Returns: 9
69
56
51
1845
Returns: 3108
73
37
26
2297
Returns: 2701
91
80
58
6431
Returns: 7280
7
49
4
125
Returns: 343
50
29
11
338
Returns: 1450
66
55
46
2702
Returns: 3630
88
87
11
1150
Returns: 7656
38
78
32
2157
Returns: 2964
8
49
5
237
Returns: 392
19
67
13
857
Returns: 1273
99
91
8
59
Returns: 8349
10
10
5
4
Returns: 16
10
3
2
2
Returns: 20
5
5
3
2
Returns: 8
10
8
5
6
Returns: 24
15
14
4
3
Returns: 48
10
10
10
1000
Returns: 100
66
37
7
20
Returns: 1092
5
5
3
6
Returns: 20
4
3
3
3
Returns: 6
3
2
2
2
Returns: 4
41
59
35
592
Returns: 1472
100
50
7
1000
Returns: 5000
5
5
3
4
Returns: 16
10
9
7
49
Returns: 90
1
4
1
1
Returns: 4
10
10
5
2
Returns: 8
100
100
100
100
Returns: 100
8
5
3
3
Returns: 18
4
5
4
4
Returns: 8