You are not logged in. Please login at www.codechef.com to post your questions!

×

AHAPH - Editorial

PROBLEM LINK:

Practice Contest

Author: vipulvikram

Tester: D Teja Vardhan Reddy

Editorialist: vipulvikram

DIFFICULTY:

MEDIUM

PREREQUISITES:

DP,Geometric progression

PROBLEM:

Given the size of an array and two integers with their index where they are already filled.Find the number of way to fill the remaining array with following conditions:

1) The numbers filled should be in range [L,R] (both inclusive).

2) consecutive positions should have different numbers.

QUICK EXPLANATION:

Let i and j are the indexes and X and Y are the corresponding integers which are already filled.

Now, The problem can be divided into 3 sub-problems. First is from index 1 to i, second is from i to j, and third is from j to n (size of array).

Now, it can be solved using dynamic programming. Let’s say we have to solve for index i to j. Index i contain X and index j contain Y. So, first we find the number of way to fill index i+1 with Y ( such that it is not equal to number in index i) , then we find the total number of ways to fill index i+2 with Y and so on till we reach index j. So the number of ways to fill up to index j with Y is its answer. But, if you observe, this series forms geometric progression which can be solved in O(logn) time.

Similarly, we find for index 1 to i, and for index j to n. Then, multiply all these three to get final answer.

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.

Tester's solution can be found here.

This question is marked "community wiki".

asked 07 Feb, 01:16

vipulvikram's gravatar image

5★vipulvikram
11
accept rate: 0%

edited 07 Feb, 20:09

admin's gravatar image

0★admin ♦♦
19.8k350498541


can someone please help me out in fun2.It is not clear to me yet.

link

answered 08 Feb, 00:06

ram_24's gravatar image

5★ram_24
1586
accept rate: 35%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×15,683
×2,172
×22
×5

question asked: 07 Feb, 01:16

question was seen: 122 times

last updated: 08 Feb, 00:06