> For the complete documentation index, see [llms.txt](https://beesec.gitbook.io/algorithms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://beesec.gitbook.io/algorithms/dynamic-programming/distinct-ways.md).

# Distinct Ways

Given a target find a number of distinct ways to reach the target.&#x20;We do this by summing all possible ways to reach the current state.

$$
routes\[i] = routes\[i-1] + routes\[i-2], ... , + routes\[i-k]
$$

An example is:

```python
d = [float("inf") for i in range(n)]
d[0] = 1
d[1] = 2
for i in range(2, n):
    d[i] = d[i - 1] + d[i - 2]
return d[-1]
```
