acgo题库
  • 首页
  • 题库
  • 学习
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情提交记录(0)
  • tj

    #include <iostream> #include <vector> #include <algorithm> #include <cstring> using namespace std; int main() { int n; cin >> n; vector<int> a(n); int total = 0; for (int i = 0; i < n; i++) { cin >> a[i]; total += a[i]; } int half = total / 2; sort(a.begin(), a.end()); bool dp[total + 1]; memset(dp, false, sizeof(dp)); dp[0] = true; int ans = 0; for (int i = n - 1; i >= 0; i--) { int x = a[i]; for (int j = total; j >= x; j--) { if (dp[j - x]) { dp[j] = true; } } int L = half + 1; int R = half + x; if (R > total) R = total; for (int j = R; j >= L; j--) { if (dp[j]) { ans = max(ans, j); break; } } } cout << ans << endl; return 0; }

    userId_undefined

    ༺ཌༀ༒☯∞复仇者∞☯༒ༀད༻™

    出道萌新时空双修者8月全勤卷王题解仙人
    1阅读
    0回复
    1点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页