← 返回 bytedance 的题目列表Can Cut All Given Squares From a Rectangle Grid
类型:online_judge
Coding: Can We Cut All Given Squares From a Rectangle Grid
You are given a rectangle of size m × n (a board/area), and a list of squares squares, where squares[i] is the side length (positive integer) of the i-th square.
Determine whether there exists a way to cut/place all these squares within the m × n rectangle.
Rules
Each square must be axis-aligned (edges parallel to the rectangle edges).
Squares must not overlap and must lie completely inside the m × n rectangle.
Leftover unused area is allowed (the rectangle does not need to be fully covered).
I/O
Input: integers m, n, and an integer array squares.
Output: true if all squares can be obtained, otherwise false.
Constraints
1 <= m, n <= 50
1 <= len(squares) <= 15
1 <= squares[i] <= 50
Examples
m = 30, n = 40, squares = [30, 10] => true
m = 30, n = 40, squares = [30, 20] => false
Tests (5)
Input: 30 40\n2\n30 10\n Output: true\n
Input: 30 40\n2\n30 20\n Output: false\n
Input: 5 5\n1\n5\n Output: true\n
Input: 5 4\n2\n4 4\n Output: false\n
Input: 6 6\n4\n3 3 3 3\n Output: true\n
Example
Input
30 40
2
30 10
Output
true