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

×

BAR3 - Editorial

PROBLEM LINK :

Contest
Practice

Author: Himanshu Sharma
Tester: Vipul Ahuja
Editorialist: Himanshu Sharma

DIFFICULTY:

Easy-Medium

PREREQUISITES:

Easy DP, Recursion.

PROBLEM:

chefs mom has collection of N chocolates. Each chocolate has different taste value. Mom has some rules, chef can eat atmost 3 chocolates in a row, to eat next chocolates he must skip atleast 1 chocolate. Chef wants to get maximum possible taste value. Find out maximum possible taste value chef can get.

QUICK EXPLANATION:

The above problem is standard DP problem.

Let DP : 2d vector for storing intermediate values.
And let V: vector of elements.

DP[1][1]=DP[1][2]=DP[1][3]=DP[1][4]=V[1];

for i in range 2 to N DP[i][0]=max(DP[i-1][0],DP[i-1][1],DP[i-1][2],DP[i-1][3]); for j in range 1 to 3 DP[i][j]=DP[i-1][j]+v[i];

result=max(DP[N][1],DP[1][2]);

Complexity of Above solution is O(N) in worst case.

Solution :

Solution from a participated Team : Solution in cpp

This question is marked "community wiki".

asked 14 Feb '18, 23:09

himanshu_1911's gravatar image

3★himanshu_1911
843
accept rate: 7%

edited 14 Feb '18, 23:11


Other Approaches are welcome. Please provide if you have one.

link

answered 14 Feb '18, 23:13

himanshu_1911's gravatar image

3★himanshu_1911
843
accept rate: 7%

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:

×2,172
×348

question asked: 14 Feb '18, 23:09

question was seen: 213 times

last updated: 14 Feb '18, 23:13