#P1397. [NOI2013] 矩阵游戏

    ID: 391 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>递推2013NOI 系列矩阵乘法线性递推,递推式

[NOI2013] 矩阵游戏

Description

Tingting is a kid who likes matrices. One day she wants to use a computer to generate a huge matrix with nn rows and mm columns (you do not need to worry about how she stores it). The matrix she generates has a magical property: let F[i,j]F[i, j] denote the element at row ii, column jj, then F[i,j]F[i, j] satisfies the following recurrence:

$$\begin{aligned} F[1, 1] &= 1 \\ F[i, j] &=a\times F[i, j-1]+b, &j\neq 1 \\ F[i, 1] &=c\times F[i-1, m]+d, &i\neq 1 \\ \end{aligned}$$

In the recurrence, a,b,c,da, b, c, d are given constants.

Now Tingting wants to know the value of F[n,m]F[n, m]. Please help her. Since the final result can be large, you only need to output the remainder of F[n,m]F[n, m] modulo 109+710^9 + 7.

Input Format

One line containing six integers n,m,a,b,c,dn, m, a, b, c, d. The meaning is as described above.

Output Format

Output a single integer, the value of F[n,m]F[n, m] modulo 109+710^9 + 7.

3 4 1 3 2 6

85

Hint

Explanation for Sample 1.

The matrix in the sample is:

$$\begin{pmatrix} 1 & 4 & 7 & 10 \\ 26 & 29 & 32 & 35 \\ 76 & 79 & 82 & 85 \\ \end{pmatrix}$$

Constraints

::cute-table{tuack}

Test point ID Constraints
1 1n,m101 \le n,m \le 10; 1a,b,c,d10001 \le a,b,c,d \le 1000
2 1n,m1001 \le n,m \le 100; 1a,b,c,d10001 \le a,b,c,d \le 1000
3 1n,m1031 \le n,m \le 10^3; 1a,b,c,d1091 \le a,b,c,d \le 10^9
4
5 1n,m1091 \le n,m \le 10^9; 1a=c1091 \le a = c \le 10^9; 1b=d1091 \le b = d \le 10^9
6 1n,m1091 \le n,m \le 10^9; a=c=1a = c = 1; 1b,d1091 \le b,d \le 10^9
7 1n,m,a,b,c,d1091 \le n,m,a,b,c,d \le 10^9
8
9
10
11 1n,m1010001 \le n,m \le 10^{1\,000}; a=c=1a = c = 1; 1b,d1091 \le b,d \le 10^9
12 1n,m1010001 \le n,m \le 10^{1\,000}; 1a=c1091 \le a = c \le 10^9; 1b=d1091 \le b = d \le 10^9
13 1n,m1010001 \le n,m \le 10^{1\,000}; 1a,b,c,d1091 \le a,b,c,d \le 10^9
14
15 1n,m10200001 \le n,m \le 10^{20\,000}; 1a,b,c,d1091 \le a,b,c,d \le 10^9
16
17 1n,m1010000001 \le n,m \le 10^{1\,000\,000}; a=c=1a = c = 1; 1b,d1091 \le b,d \le 10^9
18 1n,m1010000001 \le n,m \le 10^{1\,000\,000}; 1a=c1091 \le a = c \le 10^9; 1b=d1091 \le b = d \le 10^9
19 1n,m1010000001 \le n,m \le 10^{1\,000\,000}; 1a,b,c,d1091 \le a,b,c,d \le 10^9
20

Translated by ChatGPT 5