Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
48378 葛潇肃 火车上的人数 C++ Accepted 4 MS 268 KB 545 2023-05-27 14:42:32

Tests(5/5):


Code:

#include <iostream> using namespace std; int main() { int a, n, m, x; cin >> a >> n >> m >> x; int up[16] = {}; int down[16] = {}; int total[16] = {}; up[1] = a; total[1] = a; for (int 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 - 2] + up[j - 1]; 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; }