[Question][1]
can anyone explain this code
[2]
Please explain how he uses MOD operation.
[1]: http://www.codechef.com/problems/WEIGHT/
[2]: http://www.codechef.com/viewsolution/442926
[Question][1]
can anyone explain this code
[2]
Please explain how he uses MOD operation.
[1]: http://www.codechef.com/problems/WEIGHT/
[2]: http://www.codechef.com/viewsolution/442926
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.