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;
}
相关推荐
永远都不秃头的程序员(互关)17 分钟前
【K-Means深度探索(十二)】K-Means项目实战:从数据到决策的完整工作流!
算法·机器学习·kmeans
散峰而望18 分钟前
【基础算法】高精度运算深度解析与优化
数据结构·c++·算法·链表·贪心算法·推荐算法
一起养小猫32 分钟前
LeetCode100天Day16-跳跃游戏II与H指数
算法·游戏
mit6.82435 分钟前
两个有序集合|状态分析
算法
平生不喜凡桃李1 小时前
LeetCode 两数之和/三数之和
算法·leetcode·两数之和·三数之和
C雨后彩虹1 小时前
中文分词模拟器
java·数据结构·算法·华为·面试
BLi4ee1 小时前
【Scholarly Notes】Adaptive Model Pruning for Federated Learning
算法·机器学习·剪枝
Remember_9931 小时前
【LeetCode精选算法】二分查找专题二
java·数据结构·算法·leetcode·哈希算法
We་ct1 小时前
LeetCode 42. 接雨水:双指针解法深度剖析与全方法汇总
前端·算法·leetcode·typescript
液态不合群1 小时前
如何提升 C# 应用中的性能
开发语言·算法·c#