#abc273g. G - Row Column Sums 2
G - Row Column Sums 2
Score : points
问题描述
计算满足以下两个条件的 阶非负整数方阵的数量,结果对 取模:
- 对于所有 ,第 行元素之和为 ;
- 对于所有 ,第 列元素之和为 。
注意:输入中给出的 和 是介于 和 之间的整数(参见约束条件)。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Find the number, modulo , of square matrices of size whose elements are non-negative integers, that satisfy both of the following two conditions:
- for all , the sum of the elements in the -th row is ;
- for all , the sum of the elements in the -th column is .
Note that and given in the input are integers between and (see Constraints).
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 1 1
0 1 2
Sample Output 1
3
The following matrices satisfy the conditions:
0 1 0
0 0 1
0 0 1
0 0 1
0 1 0
0 0 1
0 0 1
0 0 1
0 1 0
Sample Input 2
3
1 1 1
2 2 2
Sample Output 2
0
Sample Input 3
18
2 0 1 2 0 1 1 2 1 1 2 0 1 2 2 1 0 0
1 1 0 1 1 1 1 1 1 1 1 1 2 1 1 0 2 2
Sample Output 3
968235177
Be sure to print the count modulo .
update @ 2024/3/10 11:31:11