QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#11315. 星露谷物语中的田园生活

统计

Panda 先生和 Panda 太太厌倦了城市的喧嚣。他们决定做出改变,放下所有的一切,搬到一个能与人和自然建立真实联系的地方。在星露谷(Stardew Valley),他们开始了农夫的生活。现在,他们正着手于开垦荒地、播种和植树的任务。

他们正在从开垦的荒地中寻找一块矩形区域来种植第一批作物。为了防止作物被讨厌的乌鸦破坏,他们在该矩形区域内放置了几个稻草人。稻草人占据一个被作物包围的矩形区域。荒地共有 $N$ 行 $M$ 列。他们想知道有多少种不同的方法来选择一个矩形区域,并在该矩形内放置作物和稻草人。由于结果可能很大,请将答案对 $10^9 + 7$ 取模。

输入格式

输入的第一行包含测试用例的数量 $T$ ($1 \le T \le 10^5$)。接下来是 $T$ 个测试用例。每个测试用例以一行开始,包含两个整数 $N, M$ ($1 \le N, M \le 10^5$),表示荒地的行数和列数。

输出格式

对于每个测试用例,输出一行 “Case x: y”,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是放置作物和稻草人的不同方法数,对 $10^9 + 7$ 取模。

样例

样例输入 1

3
2 3
3 3
4 4

样例输出 1

Case 1: 0
Case 2: 1
Case 3: 25

说明

对于测试用例 1,荒地太小,无法放置任何稻草人。

对于测试用例 2,$3 \times 3$ 是放置一个被 8 个作物包围的稻草人的最小矩形。

对于测试用例 3,一个 $4 \times 4$ 的矩形有 9 种放置作物和稻草人的方法:$1 \times 1$ 的稻草人有 4 种方法,$1 \times 2$ 的稻草人有 2 种方法,$2 \times 1$ 的稻草人有 2 种方法,以及 $2 \times 2$ 的稻草人有 1 种方法。类似地,两个 $3 \times 4$ 的矩形有 $2 \times 3 = 6$ 种方法;两个 $4 \times 3$ 的矩形有 $2 \times 3 = 6$ 种方法;四个 $3 \times 3$ 的矩形有 $4 \times 1 = 4$ 种方法。总计 $9 + 6 + 6 + 4 = 25$ 种方法。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.