The TransCompilator

Solved LeetCode program · 857 of 1,000

#1155 · Number of Dice Rolls With Target Sum

Medium Dynamic Programming chunk-18.md

Original English source

The dice is 2. The faces is 6. The wanted is 7. The width is wanted plus 1. The size is (dice plus 1) times width. The ways is a list of size zeros. Set item 0 of ways to 1.
For every die from 1 to dice.
For every sum from 1 to wanted.
For every face from 1 to faces.
If sum is at least face.
The earlier is sum minus face. The here is die times width plus sum. The before is (die minus 1) times width plus earlier. The gain is item before of ways. Set item here of ways to (item here of ways plus gain) modulo 1000000007.

The answer is item (dice times width plus wanted) of ways. Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

6