UVA Live 3704 Cellular automaton (cyclic matrix + fast Power) __ Simple Math

Source: Internet
Author: User
Description

A cellular automaton is a collection of cells on a grid of speciﬁed shape this evolves through a number of discrete time s Teps according to a set of rules this describe the new state of a cell based on the states of neighboring. The order of the cellular automaton is the number of cells it contains. Cells of the automaton of order n are numbered from 1 to N.

The order of the ' cell is ' the number of diﬀerent values it may contain. Usually, the values of a cell of order m are considered to is integer numbers from 0 to m−1.

One of the most fundamental properties of a cellular automaton is the type of grid in which it is computed. In this problem we examine the special kind of cellular automaton-circular cellular automaton of order n with cells of O Rder m. We'll denote such kind of cellular automaton as N,m−automaton.

A distance between cells I and J-N,m-automaton is deﬁned as min (|i−j|,n−|i−j|). A denvironment of a cell is the set of cells at a distance not greater than D.

On each d-step values of the all cells are simultaneously replaced by new values. The new value of cell I after d-step are computed as a sum of values of cells belonging to the d-enviroment of the cell i m Odulo m.

The following picture shows 1-step of the 5,3-automaton.

Input

The Inputﬁle contains several test cases, each of them consists of two, as lines described.

Theﬁrst line of the input contains four integer numbers n, m, D, and K (1≤n≤500, 1≤m≤1000000, 0≤d < n 2, 1 ≤k≤10000000).

The second line contains n integers numbers from 0 to m−1-initial values of the automaton ' s cells.

Output

For each test case, write to the output and on a line by itself, the values of the N,m-automaton's cells after K d-steps.

Sample Input

```5 3 1 1 1 2 2 1 2 5 3 1 1 2 2 1 2

```

Sample Output

```2 2 2 2 1 2 0 0 2 2

```

the

A cellular automaton contains n squares, the value of each lattice is (0,m), given the distance d, the value of each lattice after each operation becomes the sum of the value of the preceding operation and modulus m of all lattices with its distance not exceeding D, and the value of each lattice after K operation is computed.

train of Thought

We consider the value of each lattice after K operation as the column vector Vk V_{k}, it is not difficult to find that Vk V_k can be obtained by a transformation of vk−1 v_{k-1}, and this transformation is the vk−1 v_{k-1 element and modulus m of the neighboring 2xd+1 2xd+1.

so the whole transformation can be described by matrix multiplication.

Set V0 v_0 as the initial column vector, when d=1 d=1:
a=⎡⎣⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢⎢110⋯ 111110⋯ 101110⋯ ⋯ 01100

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.