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

×

MAXCANDY - Editorial

Maximum Candies

Tags: Dynamic Programming, Recursion with memoization.

PROBLEM LINK :
practice

Author: Shami.
Tester: Kaustav

It may be tempting to solve this problem with greedy strategy but, as the example shows, it gives the wrong answer.

To reach (i, j), there are two options (i-1, j) or (i, j-1) (for legal values of i and j). Let’s just iterate through both of them and take the maximum.

Just don’t forget to cache the values, or it will become an exponential time algorithm!

Top Down (Recursion with memoization)

Bottom up (DP)

asked 12 Jan, 14:09

mmmreddy's gravatar image

0★mmmreddy
121
accept rate: 0%

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:

×116
×1

question asked: 12 Jan, 14:09

question was seen: 83 times

last updated: 12 Jan, 14:09