#P8614. [蓝桥杯 2014 省 A] 波动数列

[蓝桥杯 2014 省 A] 波动数列

Problem Description

Observe the sequence:

1,3,0,2,1,1,2,1,3,0,2,-1,1,-2, \cdots.

In this sequence, each next term is always either increased by 22 from the previous term, or decreased by 33.

Dongdong is very curious about this kind of sequence. He wants to know: how many integer sequences are there with length nn and sum ss, such that each next term is always either increased by aa from the previous term, or decreased by bb?

Input Format

The first line contains four integers n,s,a,bn, s, a, b, 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 100000007100000007.

4 10 2 3
2

Hint

【Sample Explanation】

The two sequences are 2 4 1 32\ 4\ 1\ 3 and 7 4 1 27\ 4\ 1\ -2.

【Constraints】

For 10%10\% of the testdata: 1n51 \le n \le 5, 0s50 \le s \le 5, 1a,b51 \le a, b \le 5.

For 30%30\% of the testdata: 1n301 \le n \le 30, 0s300 \le s \le 30, 1a,b301 \le a, b \le 30.

For 50%50\% of the testdata: 1n501 \le n \le 50, 0s500 \le s \le 50, 1a,b501 \le a, b \le 50.

For 70%70\% of the testdata: 1n1001 \le n \le 100, 0s5000 \le s \le 500, 1a,b501 \le a, b \le 50.

For 100%100\% of the testdata: 1n10001 \le n \le 1000, 109s109-10^9 \le s \le 10^9, 1a,b1061 \le a, b \le 10^6.

Time limit: 1 second, 256 MB. Lanqiao Cup 2014, the 5th Provincial Contest.

Translated by ChatGPT 5