Responsive image

问题 1817 --RXD and numbers

1817: RXD and numbers

时间限制: 4 Sec  内存限制: 128 MB
提交: 1  解决: 1
[提交][状态][讨论版][命题人:]

题目描述

RXD has a sequence A1,A2,A3,…An, which possesses the following properties:
1≤Ai≤m
A1=An=1
- for all 1≤x≤m, there is at least one position p where Ap=x.
- for all x,y, the number of i(1≤i<n) which satisfies Ai=x and Ai+1=y is Dx,y.
One day, naughty boy DXR clear the sequence.
RXD wants to know, how many valid sequences are there.
Output the answer module 998244353.
0≤Di,j<500,1≤m≤400
n≥2

输入描述

There are several test cases, please keep reading until EOF.
There are about 10 test cases, but only 1 of them satisfies m>50
For each test case, the first line consists of 1 integer m, which means the range of the numbers in sequence.
For the next m lines, in the i-th line, it consists of m integers, the j-th integer means Di,j.
We can easily conclude that n=1+∑mi=1∑mj=1Di,j.

输出描述

For each test case, output "Case #x: y", which means the test case number and the answer.
 

样例输入

2
1 2
2 1
4
1 0 0 2
0 3 0 1
2 1 0 0
0 0 3 1
4
0 1 0 0
1 0 0 0
0 0 0 1
0 0 1 0

样例输出

Case #1: 6
Case #2: 18
Case #3: 0

来源

 

[提交][状态]
ACM算法攻关部