favorite We need a little bit of your help to keep things running, click on this banner to learn more

2015 German Collegiate Programming Contest (GCPC)


The computer science Professor Toving Liles loves the floor tiles in his office so much that he wants to protect them from damage by careless students. Therefore, he would like to buy cheap small rectangular carpets from the supermarket and cover the floor such that:

  1. The entire floor is covered.

  2. The carpets do not overlap.

  3. The carpets are rotated arbitrarily.

  4. No carpet is cut into pieces.

But when checking the supermarket’s stock he begins to wonder whether he can accomplish his plan at all. Can you help him?


The first line contains two integers w and h describing the size of his room (1w, h100). The second line contains an integer c (1c7), denoting the number of different carpet colours the supermarket has in stock.

Each of the following c lines consists of three integers ai, wi and hi, which means: the supermarket’s stock contains ai carpets of size wi, hi and color i (1ai7, 1wi100, 1hi100).

The supermarket has at most 7 carpets, i.e. sum of ai7.


For the given room dimensions and the supermarket’s stock of carpets, print "yes" if it is possible to cover the room with carpets as specified above and "no" otherwise.

Time limit 2 seconds
Memory limit 128 MiB
Input example #1
2 4
3 1 3
2 2 1
Output example #1
Input example #2
100 100
4 42 42
1 100 16
1 32 42
Output example #2
Source 2015 German Collegiate Programming Contest (GCPC), June 20, Problem D