A8353 | Three Sons
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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<=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.
输入输出样例
输入 #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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted