原来上车下车人数是可以为0的
#include <bits/stdc++.h>
using namespace std;
const int maX = 10000 + 5;
int a, b, c, d;
int work(int i)
{
int sum[30], up[30];
sum[1] = a;
up[1] = a;
sum[2] = a;
up[2] = i;
for (int l = 3; l < b; l++)
{
sum[l] = sum[l - 1] + up[l - 2];
up[l] = up[l - 1] + up[l - 2];
}
if (sum[b - 1] == c)
return 1;
return 0;
}
int main()
{
int i;
cin >> a >> b >> c >> d;
for (i = 0;; i++)
{
if (work(i) == 1)
break;
}
int sum[50], up[50];
sum[1] = a;
up[1] = a;
sum[2] = a;
up[2] = i;
if (d == 1 || d == 2)
{
cout << a;
return 0;
}
for (int l = 3; l <= d; l++)
{
sum[l] = sum[l - 1] + up[l - 2];
up[l] = up[l - 1] + up[l - 2];
}
cout << sum[d];
return 0;
}