Run ID:48376
提交时间:2023-05-27 14:39:26
//#include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; int main() { //freopen("a.in", "r", stdin); //freopen("b.out", "w", stdout); /* 1 2 3 4 5 total a a up a down */ int total[16] = {}; int up[16] = {}; int down[16] = {}; int a, n, m, x, i; //a为第一站上车人数 //n为总站数 //m为倒数第二站车上人数 //x为所求站开出的人数 cin >> a >> n >> m >> x; up[1] = a; total[1] = a; down[1] = 0; for (i = 0; i <= m; i++) { //第二站 up[2] = i; down[2] = i; total[2] = a; for (int j = 3; j < n; j++) { up[j] = up[j-1] + up[j-2]; down[j] = up[j-1]; total[j] = total[j-1] + up[j] - down[j]; } if (total[n-1] == m) { cout << total[x] << endl; return 0; } } cout << "No answer." << endl; return 0; }