CF120D.Three Sons

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Three sons inherited from their father a rectangular corn fiend divided into n × m squares. For each square we know how many tons of corn grows on it. The father, an old farmer did not love all three sons equally, which is why he bequeathed to divide his field into three parts containing A, B and C tons of corn.

The field should be divided by two parallel lines. The lines should be parallel to one side of the field and to each other. The lines should go strictly between the squares of the field. Each resulting part of the field should consist of at least one square.

Your task is to find the number of ways to divide the field as is described above, that is, to mark two lines, dividing the field in three parts so that on one of the resulting parts grew A tons of corn, B on another one and C on the remaining one.

三位儿子从父亲那里继承了一块矩形玉米田,该田地被划分为 n×mn \times m 个方格。对于每个方格,我们知道其上种植的玉米吨数。这位老农父亲并不 equally 爱他的三个儿子,因此他遗嘱要求将田地划分为三部分,分别包含 AA、BB 和 CC 吨玉米。

田地必须用两条平行直线划分。这两条直线应与田地的一边平行,且彼此平行。直线必须严格画在田地的方格之间(即不能穿过任何方格内部)。每一块划分出的田地部分至少需包含一个方格。

你的任务是求出满足上述条件的划分方式数目,即:确定两条直线的位置,将田地恰好划分为三部分,使得其中一部分的玉米总产量为 AA 吨,另一部分为 BB 吨,剩余一部分为 CC 吨。

输入格式

The first line contains space-separated integers n and m — the sizes of the original (1 ≤ n, m ≤ 50, max(n, m) ≥ 3). Then the field's description follows: n lines, each containing m space-separated integers c__ij, (0 ≤ c__ij ≤ 100) — the number of tons of corn each square contains. The last line contains space-separated integers A, B, C (0 ≤ A, B, C ≤ 106).

第一行包含两个用空格分隔的整数 nn 和 mm —— 原始网格的尺寸(满足 1≤n,m≤501 \leq n, m \leq 50,且 max⁡(n,m)≥3\max(n, m) \geq 3)。随后是网格的描述:共 nn 行,每行包含 mm 个用空格分隔的整数 cijc_{ij}(0≤cij≤1000 \leq c_{ij} \leq 100),表示每个方格中玉米的吨数。最后一行包含三个用空格分隔的整数 AA、BB、CC(0≤A,B,C≤1060 \leq A, B, C \leq 10^6)。

输出格式

Print the answer to the problem: the number of ways to divide the father's field so that one of the resulting parts contained A tons of corn, another one contained B tons, and the remaining one contained C tons. If no such way exists, print 0.

输出该问题的答案:将父亲的田地划分的方法数,使得其中一部分含有 AA 吨玉米,另一部分含有 BB 吨玉米,剩余部分含有 CC 吨玉米。若不存在这样的划分方式,则输出 0。

输入输出样例

  • 输入#1

    3 3
    1 1 1
    1 1 1
    1 1 1
    3 3 3

    输出#1

    2
  • 输入#2

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

    输出#2

    3
  • 输入#3

    3 3
    1 2 3
    3 1 2
    2 3 1
    5 6 7

    输出#3

    0

说明/提示

The lines dividing the field can be horizontal or vertical, but they should be parallel to each other.

划分田地的线可以是水平的或垂直的,但它们应彼此平行。

输入解题思路,AI测评打分。不知道怎么写?

首页