0이 없는 k진 정수 가운데 각 숫자의 개수가 금지된 값을 피하는 것의 수를, 금지 행렬을 한 칸씩 뒤집는 m번의 변화에 걸쳐 모두 더해 구한다.
어려움8조합론동적 계획법수학아직 제출이 없습니다시간 제한1.5초메모리 제한512 MBLittle Q likes positive big integers in base k notation, but not all of them. He doesn't like integers with zeroes, including leading zeroes. Additionally, he is particular about the number of occurrences of each digit. Formally, his preferences can be described as a binary matrix g_1..k−1,0..n, where for every digit i from 1 to k−1, if g_i,j=0, he doesn't like integers which contain exactly j copies of digit i. He also can't accept any digit appearing more than n times. The integer must contain at least one digit.
Little Q's taste changes every day. There are m days in total, and on day i, the value g_u_i,v_i is flipped (0 becomes 1 and 1 becomes 0). Let cnt(i) denote the number of big integers which Little Q likes after i-th day's change, and cnt(0) denote the answer before all changes. Your task is to calculate the following:
(∑_i=0mcnt(i))mod786,433.
The first line of the input contains three integers k, n and m: the base, the upper limit and the number of days (3≤k≤10, 1≤n≤1.4⋅104, 1≤ m≤200).
In the next k−1 lines, line i contains n+1 integers g_i,0, g_i,1, …, g_i,n (0≤g_i,j≤1). Together they provide the initial matrix g.
After that follow m lines, i-th line contains two integers u_i and v_i which mean that on i-th day, the value g_u_i,v_i is flipped (1≤u_i≤k−1, 0≤v_i≤n).
Print a single line with a single integer: the answer to the problem.