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

×

Weight of numbers - please help!

Question can anyone explain this code Code

Please explain how he uses MOD operation.

asked 03 Oct '12, 14:32

prakhs123's gravatar image

4★prakhs123
33641019
accept rate: 3%

edited 03 Oct '12, 14:43


The solution uses dynamic programming approach.
In this problem , you can keep (number of digits , current weight , previous digit used) as a state and find the number of ways accordingly .State Transition is simple as : you can try each digit from 0 to 9 , and check if its weight is within limits,then add it to the answer.

The MOD operation is simple. Since the answer can be really big, instead of storing the final answer and taking the modulus , you can take the modulus at each step , thus keeping the number within the range. You may find Modular Arithmetic useful.

link

answered 03 Oct '12, 17:03

javadecoder's gravatar image

4★javadecoder
6271713
accept rate: 27%

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:

×3,820
×3

question asked: 03 Oct '12, 14:32

question was seen: 2,092 times

last updated: 03 Oct '12, 17:03