Canadian Computing Competition: 2024 Stage 1, Senior #5
Maxwell has a chocolate bar that he wants to share with his friends. The chocolate bar can be represented as a
A part is considered connected if you can visit every cell by moving up, down, left or right.
Input Specification
The first line of input will consist of one positive integer
The second line of input contains
Similarly, the third line of input contains
The following table shows how the available 15 marks are distributed:
Marks | Bounds on |
Bounds on |
---|---|---|
2 | ||
2 | ||
1 | ||
2 | ||
2 | ||
3 | ||
3 |
Output Specification
Output a single integer, representing the maximum number of connected parts Maxwell can split his chocolate bar into.
Sample Input 1
2
5 4
6 5
Output for Sample Input 1
2
Explanation of Output for Sample Input 1
An example of how to split this chocolate bar optimally into
Each piece will have an average tastiness of
Sample Input 2
5
1 0 1 2 0
0 2 0 3 1
Output for Sample Input 2
5
Explanation of Output for Sample Input 2
One way to get the optimal split is shown in the following picture:
Note that each piece has an average tastiness of
Comments
This is the wierdest dp I have ever seen
Excuse my ignorance, but what's a DP?
It stands for Dynamic Programming, and is a category of problems