#abc345d. D - Tiling

D - Tiling

Score: 450450 points

问题陈述

有一个由 HH 行和 WW 列组成的网格,每个单元格的边长为 11,我们有 NN 块瓷砖。 第 ii 块瓷砖(1iN1\leq i\leq N)是一个大小为 Ai×BiA_i\times B_i 的矩形。 确定是否可能将瓷砖放置在网格上,以满足以下所有条件:

  • 每个单元格恰好被一块瓷砖覆盖。
  • 有未使用的瓷砖是可以接受的。
  • 放置瓷砖时可以旋转或翻转。然而,每个瓷砖必须与单元格的边缘对齐,不得延伸到网格外部。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a grid of HH rows and WW columns, each cell having a side length of 11, and we have NN tiles.
The ii-th tile (1iN1\leq i\leq N) is a rectangle of size Ai×BiA_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

  • 1N71\leq N\leq 7
  • 1H,W101 \leq H,W \leq 10
  • 1Ai,Bi101\leq A_i,B_i\leq 10
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN HH WW

A1A_1 B1B_1

A2A_2 B2B_2

\ldots

ANA_N BNB_N

Output

If it is possible to place the tiles on the grid so that all of the conditions in the problem statement are satisfied, print Yes; otherwise, print No.

Sample Input 1

5 5 5
1 1
3 3
4 4
2 3
2 5

Sample Output 1

Yes

Placing the 22-nd, 44-th, and 55-th tiles as shown below covers every cell of the grid by exactly one tile.

Hence, print Yes.

Sample Input 2

1 1 2
2 3

Sample Output 2

No

It is impossible to place the tile without letting it extend outside the grid.
Hence, print No.

Sample Input 3

1 2 2
1 1

Sample Output 3

No

It is impossible to cover all cells with the tile.
Hence, print No.

Sample Input 4

5 3 3
1 1
2 2
2 2
2 2
2 2

Sample Output 4

No

Note that each cell must be covered by exactly one tile.

update @ 2024/5/16 17:16:52