题库首页 › 信息学奥赛 › 题目 14811

阅读程序(2) 7-12题 组合题 #include #include using namespace std; int n, a[1005]; struct Node { int h, j, m, w; Node(const int _h, const int _j, const int _m, const int _w): h(_h), j(_j), m(_m), w(_w) { } Node operator+(const Node &o) const { return Node( max(h, w + o.h), max(max(j, o.j), m + o.h), max(m + o.w, o.m), w + o.w); } }; Node solve1(int h, int m) { if (h > m) return Node(-1, -1, -1, -1); if (h == m) return Node(max(a[h], 0), max(a[h], 0), max(a[h], 0), a[h]); int j = (h + m) >> 1; return solve1(h, j) + solve1(j + 1, m); } int solve2(int h, int m) { if (h > m) return -1; if (h == m) return max(a[h], 0); int j = (h + m) >> 1; int wh = 0, wm = 0; int wht = 0, wmt = 0; for (int i = j; i >= h; i--) { wht += a[i]; wh = max(wh, wht); } for (int i = j + 1; i > n; for (int i = 1; i > a[i]; cout << solve1(1, n).j << endl; cout << solve2(1, n) << endl; return 0; } 假设输入的所有数的绝对值都不超过 1000,完成下面的判断题和单选题:

正确答案:判断题答案A。solve1.j与solve2均求最大连续子段和,输出两行相等,正常执行,正确。

试卷来源:2021 CSP-S提高级(第一轮)C++真题

本卷相关题目

在线做题 同科目题库