#C411. Climbing Stairs with Variable Step Sizes

    ID: 47612 Type: Default 1000ms 256MiB

Climbing Stairs with Variable Step Sizes

Climbing Stairs with Variable Step Sizes

You are given a staircase with n steps. You can climb the staircase by taking steps of any size from 1 up to m. Your task is to compute the number of distinct ways to reach exactly the nth step. The recurrence relation that governs the process is given by:

$$dp[i] = \sum_{j=1}^{\min(m,i)} dp[i-j]$$

where dp[i] represents the number of ways to reach step i with the base case dp[0] = 1. This problem tests your understanding of dynamic programming and counting techniques.

inputFormat

The input is provided via standard input (stdin) as two space-separated integers:

  • n (1 ≤ n ≤ 104): the total number of steps in the staircase.
  • m (1 ≤ m ≤ n): the maximum step size you are allowed to take.

outputFormat

Output a single integer to standard output (stdout) representing the total number of distinct ways to climb the staircase.

## sample
5 2
8