Yet Another Expression Mining
Time limit2sMemory limit512 MB
Count subsequences of a string of digits and plus signs, with no leading, trailing, or doubled plus, whose arithmetic evaluation equals A.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
You are given an integer and a string consisting of the following 10 characters: the addition operator '+' and the digits '1', '2', ..., '9'.
Count the subsequences of that satisfy all of the following conditions.
- The subsequence is not empty.
- The first character of the subsequence is not '
+'. - The last character of the subsequence is not '
+'. - '
+' does not appear consecutively in the subsequence. - Reading the subsequence as a mathematical expression, its evaluation result is .
A subsequence is a sequence that can be obtained from the given sequence by removing zero or more elements without changing the order of the remaining elements.
Two subsequences are considered different if the sets of indices of the removed elements differ.
Input
The input consists of a single test case in the format below.
The first line contains a single string (). Each character of is either '+' or a digit between '1' and '9'. The second line contains a single integer ().
Output
Output the number of subsequences that satisfy the given conditions in a single line.