#P8786. Li Bai's Wine Journey

    ID: 21950 Type: Default 1000ms 256MiB

Li Bai's Wine Journey

Li Bai's Wine Journey

In this problem, the legendary poet Li Bai starts his journey with a wine pot containing \(2\) dou of wine. As he strolls along, he encounters two types of events: a shop and a flower. When he meets a shop, his wine gets doubled (i.e. his current amount is multiplied by 2). When he meets a flower, he drinks exactly \(1\) dou of wine (i.e. his current wine decreases by 1). Note that meeting a flower is only allowed if he currently has at least \(1\) dou of wine, while encountering a shop is always legal even if the wine pot is empty (0 dou remains 0 even when doubled).

Li Bai encounters a total of \(N\) shops and \(M\) flowers along his way. It is known that the last event he encounters is a flower and at that moment he exactly finishes his wine (i.e. his wine becomes 0 dou). Your task is to compute the number of different orders of events (shops and flowers) that satisfy these conditions.

Note: The order of events matters and the events are applied sequentially. The process is as follows: Starting with \(2\) dou, for each shop event, the wine is doubled; for each flower event, \(1\) is subtracted from the current amount. You must have exactly \(N\) shop events and \(M\) flower events, with the final event being a flower, and the pot becomes 0 dou at the end.

Hint: One way to solve the problem is to observe that if we fix the last event as a flower (which subtracts 1), then the preceding \(N + M - 1\) events must take the wine amount from \(2\) to \(1\). You can use dynamic programming (or recursion with memoization) and count the number of valid sequences that make the transition from an initial amount to \(1\) using exactly \(N\) shops and \(M-1\) flowers.

inputFormat

The input consists of a single line containing two integers \(N\) and \(M\) (with \(M \ge 1\)), representing the number of shops and the number of flowers encountered along the journey, respectively.

It is guaranteed that the last encountered event is a flower.

outputFormat

Output a single integer representing the number of valid orders (sequences) of events that satisfy the conditions.

sample

0 2
1