#P8614. [蓝桥杯 2014 省 A] 波动数列
[蓝桥杯 2014 省 A] 波动数列
Problem Description
Observe the sequence:
.
In this sequence, each next term is always either increased by from the previous term, or decreased by .
Dongdong is very curious about this kind of sequence. He wants to know: how many integer sequences are there with length and sum , such that each next term is always either increased by from the previous term, or decreased by ?
Input Format
The first line contains four integers , with the meanings described above.
Output Format
Output one line containing one integer, the number of valid sequences. Since this number is very large, output the remainder of the answer modulo .
4 10 2 3
2
Hint
【Sample Explanation】
The two sequences are and .
【Constraints】
For of the testdata: , , .
For of the testdata: , , .
For of the testdata: , , .
For of the testdata: , , .
For of the testdata: , , .
Time limit: 1 second, 256 MB. Lanqiao Cup 2014, the 5th Provincial Contest.
Translated by ChatGPT 5