Statistics

Problem Statement for "MaxPlanting"

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

  1. 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

  2. 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

  3. 10

    10

    4

    5

    Returns: 42

  4. 3

    3

    2

    3

    Returns: 8

  5. 3

    3

    2

    5

    Returns: 9

  6. 69

    56

    51

    1845

    Returns: 3108

  7. 73

    37

    26

    2297

    Returns: 2701

  8. 91

    80

    58

    6431

    Returns: 7280

  9. 7

    49

    4

    125

    Returns: 343

  10. 50

    29

    11

    338

    Returns: 1450

  11. 66

    55

    46

    2702

    Returns: 3630

  12. 88

    87

    11

    1150

    Returns: 7656

  13. 38

    78

    32

    2157

    Returns: 2964

  14. 8

    49

    5

    237

    Returns: 392

  15. 19

    67

    13

    857

    Returns: 1273

  16. 99

    91

    8

    59

    Returns: 8349

  17. 10

    10

    5

    4

    Returns: 16

  18. 10

    3

    2

    2

    Returns: 20

  19. 5

    5

    3

    2

    Returns: 8

  20. 10

    8

    5

    6

    Returns: 24

  21. 15

    14

    4

    3

    Returns: 48

  22. 10

    10

    10

    1000

    Returns: 100

  23. 66

    37

    7

    20

    Returns: 1092

  24. 5

    5

    3

    6

    Returns: 20

  25. 4

    3

    3

    3

    Returns: 6

  26. 3

    2

    2

    2

    Returns: 4

  27. 41

    59

    35

    592

    Returns: 1472

  28. 100

    50

    7

    1000

    Returns: 5000

  29. 5

    5

    3

    4

    Returns: 16

  30. 10

    9

    7

    49

    Returns: 90

  31. 1

    4

    1

    1

    Returns: 4

  32. 10

    10

    5

    2

    Returns: 8

  33. 100

    100

    100

    100

    Returns: 100

  34. 8

    5

    3

    3

    Returns: 18

  35. 4

    5

    4

    4

    Returns: 8


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: