P2392 kkksc03考前临时抱佛脚

这道题确实经典,看似贪心,实际压根贪不出来,是dp或者搜索

从这道题总结的经验: 一旦出现看似很正确,但却就是改不出AC的代码,那就可能是自己对算法知识想错了,压根不是这个点,就要考虑换思路了

复制代码
// Problem: P2392 kkksc03考前临时抱佛脚
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P2392
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// Date: 2023-12-07 20:04:03
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define endl '\n'
#define int int64_t
using namespace std;
int s[5], a[5][60],minn,ans;
void dfs(int x,int y,int ls,int rs) {
    if (x > s[y]) {
        minn = min(minn, max(ls, rs));
        return;
    }
    dfs(x + 1, y, ls + a[y][x], rs);
    dfs(x + 1, y, ls, rs + a[y][x]);
}
signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s[1] >> s[2] >> s[3] >> s[4];
    for (int i = 1; i <= 4; ++i) {
        for (int j = 1; j <= s[i]; ++j) cin >> a[i][j];
        sort(a[i] + 1, a[i] + s[i] + 1);
        minn = INT_MAX;
        dfs(1, i, 0, 0);
        ans += minn;
 //       cout << " ans  = " << ans << endl;
    }
    cout << ans << endl;
    return 0;
}
相关推荐
hanlin031 分钟前
刷题笔记:力扣第169题-多数元素
笔记·算法·leetcode
hfywmsj8 分钟前
广州餐饮铺位招租数据建模:基于多维评估体系的选址算法设计与实现
人工智能·算法·广州餐饮铺位招租
wabs66616 分钟前
关于二叉树【力扣116.填充每个节点的下一个右侧节点指针的思考】
数据结构·c++·算法·leetcode·二叉树·层序遍历
Nil20830 分钟前
leetcode 74搜索二维矩阵
算法·leetcode·矩阵
新知图书37 分钟前
第 14 章 后训练算法GRPO详解与实战
人工智能·算法
shirsl3 小时前
算法 Day1-数组 / 哈希 + 双指针
python·算法·哈希算法
2601_9677607810 小时前
2026年PDF压缩与页码添加工具技术实测:性能、算法与本地化适配深度对比
算法·pdf
不会就选b11 小时前
算法日常・每日刷题--<贪心>7
数据结构·算法·leetcode
moonrailgun11 小时前
用 Node.js 复刻 Codex Astra 的终端星光
前端·javascript·算法
罗西的思考11 小时前
[Agent Memory / 强化学习] MemPO源码学习笔记 ---(1)--- 总体
人工智能·算法·机器学习