There are six sorts of activities:  R: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,((j−2)modn)+1;  L: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,(jmodn)+1;    D: consistently shift all columns down, officially, set the worth of each ai,j to a((i−2)modn)+1,j

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter19: Probabilistic Dynamic Programming
Section19.4: Further Examples Of Probabilistic Dynamic Programming Formulations
Problem 7P
icon
Related questions
Question

Correct answer will be upvoted else Multiple Downvoted. Computer science.

There are six sorts of activities: 

R: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,((j−2)modn)+1; 

L: consistently shift all sections to one side, officially, set the worth of each ai,j to ai,(jmodn)+1; 

 

D: consistently shift all columns down, officially, set the worth of each ai,j to a((i−2)modn)+1,j; 

 

U: consistently shift all lines up, officially, set the worth of each ai,j to a(imodn)+1,j; 

 

I: supplant the stage read passed on to squarely in each column with its reverse. 

 

C: supplant the stage read start to finish in every section with its converse. 

 

Opposite of a change p1, p2, … , pn is a stage q1, q2, … , qn, to such an extent that pqi=i for each 1≤i≤n. 

 

One can see that after any grouping of activities each line and each segment of the lattice will in any case be a change of 1,2,… ,n. 

 

Given the underlying grid portrayal, you should handle m activities and output the last lattice. 

 

Input 

 

The principal line contains a solitary integer t (1≤t≤1000) — number of experiments. t experiment depictions follow. 

 

The primary line of each experiment portrayal contains two integers n and m (1≤n≤1000,1≤m≤105) — size of the lattice and number of tasks. 

 

Every one of the following n lines contains n integers isolated by single spaces — portrayal of the framework a (1≤ai,j≤n). 

 

The last line of the portrayal contains a line of m characters depicting the tasks all together, as indicated by the arrangement above. 

 

The amount of n doesn't surpass 1000, and the amount of m doesn't surpass 105. 

 

Output 

 

For each experiment, print n lines with n integers each — the last grid after m activities.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Lease Option
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole