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;
}
相关推荐
txzrxz2 分钟前
二分图详解
数据结构·c++·算法·图论·深度优先搜索·二分图染色
gaosushexiangji28 分钟前
数字图像相关DIC系统在结构振动模态测量中的应用
算法
KaMeidebaby38 分钟前
卡梅德生物技术快报|如何制备单克隆抗体:小众禽类靶点单抗制备实操流程:双载体抗原交叉筛选完整工艺记录
人工智能·python·深度学习·算法·机器学习
北域码匠1 小时前
Karatsuba乘法超详细解析(原理+流程+性能分析+纯原生C#无第三方库完整实现)
算法·c#·大数乘法·高精度计算·数据结构与算法·分治算法·karatsuba 乘法
fpcc2 小时前
数据结构和算法—数学的应用
数据结构·c++·算法
皓月斯语2 小时前
B4451 [GESP202512 四级] 建造 题解
数据结构·c++·算法·题解
z小猫不吃鱼3 小时前
模型剪枝经典论文精读:DepGraph: Towards Any Structural Pruning
算法·机器学习·剪枝
Ulyanov3 小时前
Python实现6-DOF刚体仿真器(下)——环境扰动与控制闭环
开发语言·python·算法·系统仿真·雷达电子对抗·导引头
牧以南歌〆4 小时前
数据结构<八>链式队列
c语言·数据结构·算法
Reart4 小时前
Leetcode 188.买卖股票的最佳时机4(718)
后端·算法