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;
}
相关推荐
地平线开发者13 小时前
【模型轻量化专题】衡量模型轻量性的指标
算法
学习星球16 小时前
OFDM技术精讲:正交性推导、循环前缀原理与80行Python链路仿真(附实测数据)
算法·面试·前端框架
alphaTao1 天前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
Interview Aid1121 天前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
顶点多余1 天前
那些在算法中适合巩固的知识点---1
java·前端·算法
罗西的思考1 天前
【Agentic RL / 强化学习框架】Molt 设计解读
人工智能·算法·机器学习
hahaha60161 天前
HLS高层次综合设计技巧--C++类和模板
图像处理·人工智能·算法·计算机视觉
多弗朗皮卡丘1 天前
算法详解4:买卖股票的最佳时机系列(上)
算法
维克兜率天2 天前
【维克】动量指标家族:RSI、ROC、CCI、Momentum全面解析
python·算法
AI情绪识别开源2 天前
检信 AI 智能推广平台(代号:JX-Promote)
人工智能·算法·erlang