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;
}
相关推荐
music&movie1 小时前
算法工程师认知水平要求总结
人工智能·算法
laocui12 小时前
Σ∆ 数字滤波
人工智能·算法
yzx9910132 小时前
Linux 系统中的算法技巧与性能优化
linux·算法·性能优化
全栈凯哥2 小时前
Java详解LeetCode 热题 100(26):LeetCode 142. 环形链表 II(Linked List Cycle II)详解
java·算法·leetcode·链表
全栈凯哥3 小时前
Java详解LeetCode 热题 100(27):LeetCode 21. 合并两个有序链表(Merge Two Sorted Lists)详解
java·算法·leetcode·链表
SuperCandyXu3 小时前
leetcode2368. 受限条件下可到达节点的数目-medium
数据结构·c++·算法·leetcode
Humbunklung3 小时前
机器学习算法分类
算法·机器学习·分类
Ai多利3 小时前
深度学习登上Nature子刊!特征选择创新思路
人工智能·算法·计算机视觉·多模态·特征选择
Q8137574604 小时前
中阳视角下的资产配置趋势分析与算法支持
算法
yvestine4 小时前
自然语言处理——文本表示
人工智能·python·算法·自然语言处理·文本表示