关注
第三题直接暴力DFS不知道能不能过? #include<iostream> #include<vector> using namespace std; void dfs(int &maxScore, int aScore, int bScore, int curScore, vector<pair<int, int>> &score, int layer) { if (aScore>0 && bScore>0 && aScore == bScore) { maxScore = curScore < maxScore? maxScore : curScore; return; } if (layer >= score.size()) return; dfs(maxScore, aScore + score[layer].first, bScore, curScore + score[layer].second, score, layer + 1); dfs(maxScore, aScore, bScore + score[layer].first, curScore + score[layer].second, score, layer + 1); dfs(maxScore, aScore, bScore, curScore, score, layer + 1); } int main() { int n; cin >> n; int x, y; vector<pair<int, int>> score; for (int i = 0; i < n; i++) { cin >> x >> y; score.push_back({ x, y }); } int res; dfs(res, 0, 0, 0, score, 0); cout << res << endl; system("pause"); return 0; }
查看原帖
点赞 4
相关推荐
查看30道真题和解析
点赞 评论 收藏
转发
牛客热帖
正在热议
# 和牛牛一起刷题打卡 #
9608次浏览 832人参与
# 机械制造薪资爆料 #
348182次浏览 4099人参与
# 牛客帮帮团来啦!有问必答 #
1057307次浏览 16015人参与
# 通信硬件薪资爆料 #
250533次浏览 2361人参与
# 晒一晒我的offer #
3726891次浏览 57554人参与
# 面试中,你被问过哪些奇葩问题? #
19314次浏览 149人参与
# 你收到了团子的OC了吗 #
525293次浏览 6240人参与
# 毕业租房也有小确幸 #
38382次浏览 3172人参与
# 你怎么评价今年的春招? #
9539次浏览 161人参与
# 我想象的工作vs实际工作 #
104203次浏览 1681人参与
# 提前批和秋招有什么区别 #
28889次浏览 695人参与
# 春招你拿到offer了吗 #
397988次浏览 5747人参与
# 秋招开了,你想投哪些公司呢 #
132443次浏览 3426人参与
# 字节跳动工作体验 #
73423次浏览 2018人参与
# 实习生应该准时下班吗 #
88406次浏览 649人参与
# 来选选带哪个offer回家过年 #
191751次浏览 1838人参与
# 你的秋招进行到哪一步了 #
392887次浏览 6641人参与
# 腾讯工作体验 #
151269次浏览 1478人参与
# 浅聊一下我实习的辛苦费 #
99327次浏览 1000人参与
# 百度工作体验 #
28544次浏览 286人参与