Responsive image

问题 1820 --Big Integer

1820: Big Integer

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

题目描述

Little Q likes positive big integers in base k, but not all big integers. He doesn't like integers with zeroes, including leading zeroes. He is even particular with the occurrence of each digit. Formally it can be described as a matrix g1..k−1,0..n, for every digit i from 1 to k−1, he doesn't like integers having exactly j-digit i when gi,j=0. He also can't accept any digit appearing more than n times.



Picture from Wikimedia Commons


Little Q's taste changes every day. There are m days in total, on i-th day gui,vi flipped(0 to 1 and 1 to 0). Let cnt(i) denotes the number of big integers Little Q likes after i-th day's change, where cnt(0) denotes the answer before all changes. Your task is to calculate the following thing :
(∑i=0mcnt(i))mod786433

输入描述

The first line of the input contains an integer T(1≤T≤5), denoting the number of test cases.

In each test case, there are 3 integers k,n,m(3≤k≤10,1≤n≤14000,1≤m≤200) in the first line, denoting the base, the upper limit and the number of days.

For the next k−1 lines, each line contains n+1 integers gi,0,gi,1,...,gi,n(0≤gi,j≤1), denoting the matrix g.

For the next m lines, each line contains 2 integers ui,vi(1≤ui≤k−1,0≤vi≤n), denoting a changed position in g.

输出描述

For each test case, print a single line containing an integer, denoting the answer.
 

样例输入

1
3 2 2
101
010
1 1
1 2

样例输出

13

提示

cnt(0)=4 : 112,121,211,2.
cnt(1)=6 : 112,121,211,2,12,21.
cnt(2)=3 : 2,12,21.

来源

 

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