问题 G: Travel

内存限制:512 MB 时间限制:12 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Alice is currently traveling in a k-dimensional space. She starts at (0,0,…,0)(0,0,,0), and she has a total of n teleportation skills. When she uses a teleportation skill, if she is at (�1,�2,…,��)(x1,x2,,xk) and the teleportation skill is (�1,�2,…,��)(y1,y2,,yk), she will be teleported to (�1+�1,…,��+��)(x1+y1,,xk+yk). Teleportation skills can be used in any way.

This k-dimensional space is finite, and the size of the i-th dimension is ��Ni. In other words, for the i-th dimension, the coordinate range is 0≤��≤��0xiNi.

Alice's destination is (N1,,Nk). There are a total of m black holes in the k-dimensional space, which means Alice cannot reach those positions in any way. Alice wants to know how many ways she can use teleportation skills to reach her destination without passing through any black holes.

We consider two different teleportation plans to be different if and only if there exists a step where the two plans use different teleportation skills.

Two teleportation skills are considered different if and only if their skill numbers are different. Even if the effects of these two skills are exactly the same, they will still be considered as two separate skills.

Since the answer can be large, please output it modulo 998244353.

输入格式

The input consists of multiple test cases. The first line contains a single integer �(1≤�≤5)T(1T5) — the number of test cases. Description of the test cases follows.

The first line of each test case contains one integers k (2≤�≤16)(2k16)—This means that the space has a total of kdimensions.

The next line contains k positive integers ��Ni (1≤��≤105)(1Ni105), representing the size of the i-th dimension.

The next line contains two integers n and m , (1≤�≤105,0≤�≤1000)(1n105,0m1000) , representing the number of teleportation skills and the number of obstacles, respectively.

The next n lines contain k non-negative integers (�1,…,��)(y1,,yk), where (∀�∈[1,�],0≤��≤��)(i[1,k],0yiNi), representing the current teleportation skills.

The next m lines contain k non-negative integers (�1,…,��)(x1,,xk), where (∀�∈[1,�],0≤��≤��)(i[1,k],0xiNi), representing the coordinates of the black holes.

It is guaranteed that there is no leap skill corresponding to (0,0,⋯,0)(0,0,,0).

The data ensures that ∏�=1�(��+1)≤2×105i=1k(Ni+1)2×105.

输出格式

For each test case, output an integer representing the number of ways Alice can reach her destination modulo 998244353.

输入样例 复制

1
2
100 1000
2 0
1 0
0 1

输出样例 复制

555294450

分类标签