PlacingPieces
SRM 316 · 2006-08-19 · by _efer_
Problem Statement
You will be given an
Constraints
- L will be between 1 and 1000, inclusive.
- pieces will contain between 1 and 30 elements, inclusive.
- Each element of pieces will be between 1 and 100, inclusive.
9
{1, 8}
Returns: 1
You can place both pieces on the board and leave no space on it. However, there is a better solution as depicted below. Place only the second piece on the board, and leave a little space between it and the left and right edges of the board, so that the first piece can't fit:
36
{1, 1, 5, 5, 5}
Returns: 4
If we place all three pieces with length 5 on the board, we will have no choice but to also place the smallest two pieces. However, if you place only two of them and the two smallest pieces, you can leave spaces on the board that are smaller than the length of the remaining piece.
37
{1, 1, 5, 5, 5}
Returns: 5
You cannot leave any piece out here.
18
{2, 2, 2, 9, 9, 10}
Returns: 2
Sometimes it is better to not place the piece with the highest length.
1
{2, 3, 4}
Returns: 0
No piece fits on this board.
Submissions are judged against all 137 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PlacingPieces with a public method int optimalPlacement(int L, vector<int> pieces) · 137 test cases · 2 s / 256 MB per case