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;
}
相关推荐
wen__xvn1 小时前
每日一题洛谷P1914 小书童——凯撒密码c++
数据结构·c++·算法
BUG 劝退师2 小时前
八大经典排序算法
数据结构·算法·排序算法
m0_748240912 小时前
SpringMVC 请求参数接收
前端·javascript·算法
小林熬夜学编程3 小时前
【MySQL】第八弹---全面解析数据库表的增删改查操作:从创建到检索、排序与分页
linux·开发语言·数据库·mysql·算法
小小小白的编程日记3 小时前
List的基本功能(1)
数据结构·c++·算法·stl·list
_Itachi__3 小时前
LeetCode 热题 100 283. 移动零
数据结构·算法·leetcode
柃歌3 小时前
【UCB CS 61B SP24】Lecture 5 - Lists 3: DLLists and Arrays学习笔记
java·数据结构·笔记·学习·算法
鱼不如渔3 小时前
leetcode刷题第十三天——二叉树Ⅲ
linux·算法·leetcode
qwy7152292581633 小时前
10-R数组
python·算法·r语言
月上柳梢头&3 小时前
[C++ ]使用std::string作为函数参数时的注意事项
开发语言·c++·算法