about a n by n chessboard. Its columns are numbered from 1 to n from the top to the base. Its sections are numbered from 1 to n from the passed on to one side. A cell on a convergence of x-th line and y-th section is indicated (x,y). The fundamental corner to corner of the chessboard is cells (x,x) for all 1≤x≤n.    A stage of {1,2,3,… ,n} is composed on the fundamental slanting

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

Computer science. Correct answer will be upvoted else downvoted.

 

Think about a n by n chessboard. Its columns are numbered from 1 to n from the top to the base. Its sections are numbered from 1 to n from the passed on to one side. A cell on a convergence of x-th line and y-th section is indicated (x,y). The fundamental corner to corner of the chessboard is cells (x,x) for all 1≤x≤n. 

 

A stage of {1,2,3,… ,n} is composed on the fundamental slanting of the chessboard. There is actually one number composed on every one of the cells. The issue is to segment the cells under and on the principle askew (there are by and large 1+2+… +n such cells) into n associated areas fulfilling the accompanying imperatives: 

 

Each district ought to be associated. That implies that we can move from any cell of a locale to some other cell of a similar area visiting just cells of a similar district and moving from a cell to a neighboring cell. 

 

The x-th area ought to contain cell on the fundamental inclining with number x for all 1≤x≤n. 

 

The number of cells that have a place with the x-th district ought to be equivalent to x for all 1≤x≤n. 

 

Every cell under and on the fundamental askew ought to have a place with precisely one area. 

 

Input 

 

The principal line contains a solitary integer n (1≤n≤500) meaning the size of the chessboard. 

 

The subsequent line contains n integers p1, p2, ..., pn. pi is the number composed on cell (i,i). It is ensured that every integer from {1,… ,n} shows up precisely once in p1, ..., pn. 

 

Output 

 

On the off chance that no arrangement exists, output −1. 

 

In any case, output n lines. The I-th line ought to contain I numbers. The j-th number on the I-th line ought to be x if cell (i,j) has a place with the area with x cells.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Binary numbers
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr