#K9961. Pipe Installation Combinations

    ID: 39146 Type: Default 1000ms 256MiB

Pipe Installation Combinations

Pipe Installation Combinations

You are given d houses arranged in a straight line. Between every two consecutive houses, there is a potential gap where a water pipe can be installed. There are d-1 such gaps. Your task is to determine the number of distinct ways to install exactly k water pipes among these gaps.

This problem can be modeled using combinatorics. The answer is given by the binomial coefficient \[ \binom{d-1}{k} = \frac{(d-1)!}{k!(d-1-k)!} \] which represents the number of ways to choose k gaps out of d-1 possible ones.

Note: It is guaranteed that the given values for d and k will be such that 0 ≤ k ≤ d-1.

inputFormat

The input consists of a single line containing two space-separated integers:

  • d: the number of houses.
  • k: the exact number of water pipes to install.

You should read the input from stdin.

outputFormat

Output a single integer representing the number of ways to install exactly k water pipes among the d houses. Print your answer to stdout.

## sample
4 2
3