Tiling

AtCoder
IDabc345_d
Time2000ms
Memory256MB
Difficulty
There is a grid of $H$ rows and $W$ columns, each cell having a side length of $1$, and we have $N$ tiles. The $i$\-th tile ($1\leq i\leq N$) is a rectangle of size $A_i\times B_i$. Determine whether it is possible to place the tiles on the grid so that all of the following conditions are satisfied: * Every cell is covered by exactly one tile. * It is fine to have unused tiles. * The tiles **may be rotated or flipped when placed**. However, each tile must be aligned with the edges of the cells without extending outside the grid. ## Constraints * $1\leq N\leq 7$ * $1 \leq H,W \leq 10$ * $1\leq A_i,B_i\leq 10$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $H$ $W$ $A_1$ $B_1$ $A_2$ $B_2$ $\ldots$ $A_N$ $B_N$ [samples]
Samples
Input #1
5 5 5
1 1
3 3
4 4
2 3
2 5
Output #1
Yes

Placing the $2$\-nd, $4$\-th, and $5$\-th tiles as shown below covers every cell of the grid by exactly one tile.
![image](https://img.atcoder.jp/abc345/0a0f2829d0485013deabba0103dbd906.png)
Hence, print `Yes`.
Input #2
1 1 2
2 3
Output #2
No

It is impossible to place the tile without letting it extend outside the grid.  
Hence, print `No`.
Input #3
1 2 2
1 1
Output #3
No

It is impossible to cover all cells with the tile.  
Hence, print `No`.
Input #4
5 3 3
1 1
2 2
2 2
2 2
2 2
Output #4
No

Note that each cell must be covered by exactly one tile.
API Response (JSON)
{
  "problem": {
    "name": "Tiling",
    "description": {
      "content": "There is a grid of $H$ rows and $W$ columns, each cell having a side length of $1$, and we have $N$ tiles.   The $i$\\-th tile ($1\\leq i\\leq N$) is a rectangle of size $A_i\\times B_i$.   Determine whet",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc345_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There is a grid of $H$ rows and $W$ columns, each cell having a side length of $1$, and we have $N$ tiles.  \nThe $i$\\-th tile ($1\\leq i\\leq N$) is a rectangle of size $A_i\\times B_i$.  \nDetermine whet...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments