Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are n colorful tiles arranged in a line T 1 , T 2 , . . . , Tn . Each tile is colored

There are n colorful tiles arranged in a line T1, T2,..., Tn. Each tile is colored with either Red,
Green or Blue color. T1 is Red.
A frog, which is currently on T1, is trying to reach Tn. However, the jumps of the frog are restricted as
follows:
1. If it is currently on tile i, then it can only jump to a tile j where j > i.
2. The sequence of the color of the tiles on which it jumps must be in the following specific order: Red,
Green, Blue, Red, Green, Blue, ....
The jumps can be arbitrarily long. However, longer jumps are harder: a jump of length k costs k k energy.
Note that the final tile Tn also has some color and thus the frog must reach it in a corresponding step.
Given an input x in {Red, Green, Blue}
n, i.e., the sequence of the colors of the tiles, design an algorithm
that returns the smallest possible total cost of doing so. If it is impossible to reach the final tile, return -1.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

How we can improve our listening skills?

Answered: 1 week ago

Question

How do artifacts affect interaction between members of the team?

Answered: 1 week ago