0% found this document useful (0 votes)
96 views4 pages

DO NOT: Red-Black Grid

Bibi learns about red-black trees and paints a grid according to its structure. She wonders how many configurations are possible if each cell is painted red or black. There are two test cases provided, with grids of sizes 1x1 and 1x2, and the number of possible configurations for each are 2 and 4 respectively.

Uploaded by

nEZ Official
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views4 pages

DO NOT: Red-Black Grid

Bibi learns about red-black trees and paints a grid according to its structure. She wonders how many configurations are possible if each cell is painted red or black. There are two test cases provided, with grids of sizes 1x1 and 1x2, and the number of possible configurations for each are 2 and 4 respectively.

Uploaded by

nEZ Official
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

E

COMP6047 – Algorithm and Programming

T
T
NO
BU
Red-Black Grid
Bibi just learned the Red-Black Tree data structure. She is really amazed by how fast
the tree can process queries. One day, she made a grid of size N × M . All of the cells
on the grid are initially painted white. Still amazed by the power of Red-Black Tree, she
decided to paint the grid with similar color to her favorite data structure.

R I
O
Bibi can paint each cells of the grid with one of the color red or black. Because she is
a perfectionist, she doesn’t want any cell to be left unpainted. That is, each of the cells
must be either red or black. Bibi wonders, how many different configurations can she
T
make satisfying all of the conditions? Two configurations are considered different if a cell
D

is painted red on one configuration and black on the other one.


S
Format Input
DI

The first line of input contains an integer T , the number of cases. The next T lines each
contains two integers N and M , which denotes the dimension of the grid.

Format Output
OT
UT
RE

For each case, output “Case #X: Y” where X is the test case number and Y is the number
of configurations.

Constraints
N
• 1 ≤ T ≤ 20
IB
• 1 ≤ N × M ≤ 60

Sample Input (standard input)


TR
DO

2
1 1
1 2
IS

Sample Output (standard output)


Case #1: 2
Case #2: 4
ED

c School of Computer Science - BINUS, 2020. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.
E
COMP6047 – Algorithm and Programming

T
T
Explanation

NO
BU
The possible configurations for the second sample are :
(Red, Black)
(Red, Red)
(Black, Red)
(Black, Black)

R I
O
T
D
S
DI

OT
UT
RE

N
IB
TR
DO
IS
ED

c School of Computer Science - BINUS, 2020. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.
T
COMP6047 – Algorithm and Programming

RI T
U
ST NO
B
Red-Black Grid
Bibi baru saja mempelajari struktur data Red-Black Tree. Dia sangat kagum dengan
betapa cepatnya struktur data tersebut dapat memproses suatu query. Suatu hari, dia
membuat grid dengan ukuran N ×M . Semua sel dalam grid pada awalnya memiliki warna
putih. Karena Bibi masih kagum dengan kekuatan dari Red-Black Tree, dia memutuskan
untuk mewarnai grid tersebut serupa dengan struktur data favoritnya.
DI O
Bibi dapat mewarnai setiap sel pada grid tersebut dengan warna merah atau hitam.
Karena dia adalah individu yang sangat perfeksionis, Dia tidak ingin ada sel yang tidak
RE D

diwarnai. Artinya, setiap sel harus berwarna hitam atau merah. Bibi penasaran, ada
berapa banyak konfigurasi berbeda yang dapat memenuhi persyaratannya? Dua buah
konfigurasi dinyatakan berbeda apabila sebuah sel berwarna merah pada suatu konfigurasi
dan berwarna hitam pada konfigurasi lainnya.

TE
Format Input
Baris pertama pada inputan berisi sebuah bilangan bulat T , yaitu jumlah kasus. T baris
RI T
berikutnya masing - masing berisi N dan M , yang menunjukkan dimensi dari grid.

BU
Format Output
ST NO
Untuk tiap kasus, keluarkan “Case #X: Y” dimana X adalah nomor kasus dan Y adalah
jumlah konfigurasi.

Constraints
• 1 ≤ T ≤ 20

• 1 ≤ N × M ≤ 60
O

Sample Input (standard input)


RE D

2
1 1
1 2
DI

c School of Computer Science - BINUS, 2020. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.
E
COMP6047 – Algorithm and Programming

T
T
Sample Output (standard output)

NO
BU
Case #1: 2
Case #2: 4

Explanation

I
Konfigurasi yang mungkin untuk sampel kasus kedua adalah :

R
(Merah, Hitam)
O
(Merah, Merah)
(Hitam, Merah)
(Hitam, Hitam)
T
D
S
DI

OT
UT
RE

N
IB
TR
DO
IS
ED

c School of Computer Science - BINUS, 2020. No part of the materials available may be copied,
photocopied, reproduced, translated, or reduced to any electronic medium or machine-readable form,
in whole or in part, without prior written consent of School of Computer Science - BINUS. Any other
reproduction in any form without the permission of School of Computer Science - BINUS is probihited.
For those who violated this disclaimer, academic sanctioned can be enforced.

You might also like