|
发表于 2022-3-18 23:32:55
|
显示全部楼层
本帖最后由 傻眼貓咪 于 2022-3-19 08:09 编辑
答案是 13 吗?- #include <iostream>
- #include <vector>
- // 开始时间、结束时间
- typedef struct {
- unsigned start, end;
- }Time;
- // 工作时间、收入
- typedef struct {
- Time time;
- unsigned income;
- }Timer;
- // 计算收入
- unsigned income(std::vector<Timer> V, Time T, unsigned sum = 0) {
- std::vector<unsigned> temp;
- unsigned max = 0;
- for (const Timer &t : V) {
- // 寻找下一个吻合的时间点路线
- if (t.time.start >= T.end) {
- temp.push_back(income(V, t.time, t.income));
- }
- }
- for (unsigned u : temp) if (u > max) max = u;
- return sum + max;
- }
- int main() {
- unsigned arr[][3] = { { 1, 4, 5 }, { 3, 5, 1 }, { 0, 6, 8 }, { 4, 7, 4 }, { 3, 8, 6 }, { 5, 9, 3 }, { 6, 10, 2 }, { 8, 11, 4 } };
- std::vector<Timer> V;
- for (int i = 0; i < 8; i++) V.push_back({ { arr[i][0], arr[i][1] }, arr[i][2] });
- unsigned max = 0;
- for (const Timer &t: V) {
- if (income(V, t.time, t.income) > max) {
- max = income(V, t.time, t.income);
- }
- }
- std::cout << max;
- return 0;
- }
复制代码 |
|