关注
第四题 暴力递归(40%) bool cmp(pair<int, int> &a, pair<int, int> &b) { if (a.first == b.first) return a.second > b.second; else return a.first > b.first; } void helper(vector<pair<int, int>> x, int max_weight, int height, int &res, int idx, int max_l) { res = max(res, height); if (idx == x.size()) return; if (x[idx].first < max_l && x[idx].second <= max_weight) { if (max_weight - x[idx].second < x[idx].second * 7) helper(x, max_weight - x[idx].second, height + 1, res, idx + 1, x[idx].first); else helper(x, x[idx].second * 7, height + 1, res, idx + 1, x[idx].first); } helper(x, max_weight, height, res, idx + 1, max_l); } int main() { int n; cin >> n; vector<int> L(n), W(n); for (int i = 0; i < n; i++) cin >> L[i]; for (int i = 0; i < n; i++) cin >> W[i]; vector<pair<int, int>> x; for (int i = 0; i < n; i++) x.push_back(make_pair(L[i], W[i])); sort(x.begin(), x.end(), cmp); int res = 0; helper(x, INT_MAX, 0, res, 0, INT_MAX); cout << res << endl; system("pause"); return 0; }
查看原帖
点赞 6
相关推荐
牛客85586392...:就团子这base 拉完了还top 点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 职场中那些令人叹为观止的八卦 #
13799次浏览 159人参与
# 秋招吐槽大会 #
52455次浏览 455人参与
# 百度秋招 #
46127次浏览 366人参与
# 我的职场社死时刻 #
11027次浏览 110人参与
# 你找工作想离家近 or 离家远? #
9701次浏览 167人参与
# 你父母给过你哪些不靠谱的职场建议? #
9199次浏览 139人参与
# 小红书开奖了 #
21800次浏览 121人参与
# 那些年,我收到的‘奇葩’回复 #
6280次浏览 61人参与
# 哪些公司开始补录了 #
11088次浏览 124人参与
# 你秋招最后悔的选择 #
9350次浏览 71人参与
# 秋招你经历过哪些无语的事 #
6026次浏览 62人参与
# XX请雇我工作 #
7992次浏览 76人参与
# 月薪多少能在一线城市生存 #
94311次浏览 677人参与
# 租房前辈的忠告 #
276603次浏览 7206人参与
# 中科曙光工作体验 #
5795次浏览 23人参与
# 如何拒绝/反向PUA #
83640次浏览 372人参与
# 假如你的老板掉河里,你的工作能为他做什么 #
40386次浏览 402人参与
# 虾皮开奖 #
51672次浏览 251人参与
# 交通银行工作体验 #
21443次浏览 69人参与
# 你觉得机械有必要实习吗 #
67286次浏览 481人参与
# 秋招提前批,你开始投了吗 #
678017次浏览 8394人参与
# 职场中对你有帮助的书 #
23936次浏览 213人参与

