#P1011. [NOIP 1998 提高组] 车站

    ID: 11 远端评测题 1000ms 125MiB 尝试: 1 已通过: 1 难度: 3 上传者: 标签>数学1998NOIp 提高组斐波那契,Fibonacci

[NOIP 1998 提高组] 车站

Description

A train departs from the origin (called station 11). At the origin, aa people board. It then arrives at station 22; at station 22 some people board and alight, but the numbers boarding and alighting are equal, so when departing station 22 (i.e., before arriving at station 33), there remain aa people on the train. From station 33 onward (including station 33), the numbers boarding and alighting follow a rule: the number boarding at each station equals the sum of the numbers who boarded at the previous two stations, and the number alighting equals the number who boarded at the previous station. This holds through the penultimate station, station n1n-1. You are given that there are nn stations in total, aa people board at the origin, and at the last station the number of people alighting is mm (everyone gets off). Find the number of people on the train when departing station xx.

Input Format

A single line containing four integers: the number of people boarding at the origin aa, the number of stations nn, the number of people alighting at the terminal station mm, and the station index to query xx.

Output Format

Output a single integer: the number of people on the train when departing station xx.

5 7 32 4

13

Hint

For all test cases, 1a201 \leq a \leq 20, 1xn201 \leq x \leq n \leq 20, 1m2×1041 \leq m \leq 2 \times 10^4.

NOIP 1998 Senior Problem 1.

Translated by ChatGPT 5