Carpets
Time limit1sMemory limit256 MB
Decide whether the given carpets, each usable rotated, cover a W by H room exactly with no overlap.
- Level
Medium6 of 10
- Topics
- Backtracking, Recursion
- Solved
- No attempts yet
Problem
Professor Toving Liles of the computer science department likes the floor tiles in his office so much that he wants to protect them from careless students. He plans to buy cheap small rectangular carpets at the supermarket and cover the floor so that all four rules hold:
- The entire floor is covered.
- No two carpets overlap.
- A carpet may be turned by 90 degrees, so a carpet can also be laid as an carpet.
- No carpet is cut into pieces.
Every carpet is laid with its sides parallel to the walls, and the professor does not have to buy the whole stock. Decide whether he can carry out his plan.
Input
The first line contains two integers and , the width and the height of the room ().
The second line contains an integer , the number of carpet colors the supermarket has in stock ().
Each of the following lines contains three integers , and , meaning that the supermarket has carpets of size in color (; ; ).
The supermarket has at most 7 carpets in total, that is .
Output
Print yes if the room can be covered under the rules above, and no otherwise.