usaco2.1.4 Healthy Holsteins

USACO 2.1.4 健康的荷斯坦奶牛 Healthy Holsteins 题解 这道题我一直想着用dp来解,因为我觉得和01背包很像。 但是这个容量数据没办法用数组表示,所以一直想不到解法。 我默认dfs是会指数爆炸的不好解法,所以一开始就没考虑,但这题的数据很弱… 代码 #include <iostream> #include <cstdio> #include <fstream> #include <cstdl... 阅读详情

一 原题

Healthy Holsteins
Burch & Kolstad

Farmer John prides himself on having the healthiest dairy cows in the world. He knows the vitamin content for one scoop of each feed type and the minimum daily vitamin requirement for the cows. Help Farmer John feed his cows so they stay healthy while minimizing the number of scoops that a cow is fed.

Given the daily requirements of each kind of vitamin that a cow needs, identify the smallest combination of scoops of feed a cow can be fed in order to meet at least the minimum vitamin requirements.

Vitamins are measured in integer units. Cows can be fed at most one scoop of any feed type. It is guaranteed that a solution exists for all contest input data.

PROGRAM NAME: holstein

INPUT FORMAT

Line 1:integer V (1 <= V <= 25), the number of types of vitamins
Line 2:V integers (1 <= each one <= 1000), the minimum requirement for each of the V vitamins that a cow requires each day
Line 3:integer G (1 <= G <= 15), the number of types of feeds available
Lines 4..G+3:V integers (0 <= each one <= 1000), the amount of each vitamin that one scoop of this feed contains. The first line of these G lines describes feed #1; the second line describes feed #2; and so on.

SAMPLE INPUT (file holstein.in)

4
100 200 300 400
3
50   50  50  50
200 300 200 300
900 150 389 399

OUTPUT FORMAT

The output is a single line of output that contains:

  • the minimum number of scoops a cow must eat, followed by:
  • a SORTED list (from smallest to largest) of the feed types the cow is given
If more than one set of feedtypes yield a minimum of scoops, choose the set with the smallest feedtype numbers.

SAMPLE OUTPUT (file holstein.out)

2 1 3


二 分析

这题最多只要枚举2^15种情况,直接枚举就行。


三 代码

运行结果:
USER: Qi Shen [maxkibb3]
TASK: holstein
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 4184 KB]
   Test 2: TEST OK [0.000 secs, 4184 KB]
   Test 3: TEST OK [0.000 secs, 4184 KB]
   Test 4: TEST OK [0.000 secs, 4184 KB]
   Test 5: TEST OK [0.000 secs, 4184 KB]
   Test 6: TEST OK [0.000 secs, 4184 KB]
   Test 7: TEST OK [0.000 secs, 4184 KB]
   Test 8: TEST OK [0.000 secs, 4184 KB]
   Test 9: TEST OK [0.000 secs, 4184 KB]
   Test 10: TEST OK [0.000 secs, 4184 KB]

All tests OK.

Your program ('holstein') produced all correct answers! This is your submission #3 for this problem. Congratulations!


AC代码:
/*
ID:maxkibb3
LANG:C++
PROG:holstein
*/

#include<cstdio>

const int MAX_N = 25;
const int MAX_M = 15;
int n, m;
int target[MAX_N];
int feeds[MAX_M][MAX_N];
int current[MAX_N];
int trace[MAX_M], trace_size;
int ans[MAX_N];

void init() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &target[i]);
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++) {
        for(int j = 0; j < n; j++) {
            scanf("%d", &feeds[i][j]);
        }
    }
}

bool enough() {
    for(int i = 0; i < n; i++) {
        if(current[i] < target[i]) return false;
    }
    return true;
}

bool judge(int left, int idx) {
    if(enough()) return true;
    if(left == 0) return false;
    if(left + idx > m) return false;
    if(judge(left, idx + 1)) {
        return true;
    }
    for(int i = 0; i < n; i++) {
        current[i] += feeds[idx][i];
    }
    trace[trace_size++] = idx;
    if(judge(left - 1, idx + 1)) {
        return true;
    }
    trace_size--;
    for(int i = 0; i < n; i++) {
        current[i] -= feeds[idx][i];
    }
    return false;
}

void solve() {
    int l = 1, r = m;
    bool first_eq = false;
    while(l <= r) {
        if(l == r) {
            if(first_eq) break;
            else first_eq = true; 
        } 
        int mid = (l + r) >> 1;
        trace_size = 0;
        for(int i = 0; i < n; i++) current[i] = 0;
        if(judge(mid, 0)) {
            r = mid;
            for(int j = 0; j < trace_size; j++) {
                ans[j] = trace[j];
            }
        }
        else {
            l = mid + 1;
        }
    }
    printf("%d ", l);
    for(int i = 0; i < l - 1; i++) {
        printf("%d ", ans[i] + 1);
    }
    printf("%d\n", ans[l - 1] + 1);
}

int main() {
    freopen("holstein.in", "r", stdin);
    freopen("holstein.out", "w", stdout);
    init();
    solve();
    return 0;
}


USACO 2.1.4 Healthy Holsteins 健康的好斯坦奶牛 DFS & 组合 Problem D: 2.1.4 Healthy Holsteins 健康的好斯坦奶牛 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 9  Solved: 6 [Submit][Status][Web Board] Description 农民JOHN以拥有世界上最健康的奶牛为骄傲。他知道每种饲料中所包含的的牛所需的最低的维他命量是 阅读详情

相关推荐

[USACO 2.1.4] Healthy Holsteins

[题目描述] Healthy Holsteins 健康的好斯坦奶牛 农民JOHN以拥有世界上最健康的奶牛为骄傲。他知道每种饲料中所包含的的牛所需的最低的维他命量是多少。请你帮助农夫喂养他的牛,以保持他们的健康,使喂给牛的饲料的种数最少。 给出牛所需的最低的维他命,输出喂给牛需要哪些种类的饲料,且所需的种类数最少。 PROGRAM NAME: holstein INPUT FORMA

_Nirvana 759

Healthy Holsteins

Problem: Healthy Holsteins Farmer John prides himself on having the healthiest dairy cows in the world. He knows the vitamin con

小爱慢慢爬行...... 696

Usaco 2.1.4 健康的荷斯坦奶牛(Healthy Holsteins)

题目:  健康的荷斯坦奶牛 来源:  Usaco2.1.4 题目大意:  给定V个值,G个方案,求通过最小的方案数使这V个值全为不大于0的数,如果有多  组方案,输出字典序最小的。 数据范围:

慢慢前行,跨越预言 1086

USACO 2.1.4 Healthy Holsteins解题报告

原题链接: 思路:仔细看题会发现G(饲料种数在1~15之间),每种饲料有两种情况,取或者不取,则总共有2^15=32768种可能,并不多可以采取枚举这32768种可能的做法解题。             注意找到一种选择之后,不必判断每一种维他命是否得到满足,比如这种选择不能使第一种维他命得到满足,则舍弃这种选择,后面的几种维他命就不必再进行             判断了,这是一种高效的做

supersnow0622的专栏 1523

NKOJ P1803 【USACO2.1.4】Healthy Holsteins健康的荷斯坦奶牛

然后确定搜索的边界,也就是x>饲料的种数,然后判断每次选的那些饲料中的维生素之和是不是都大于等于牛每天需要的每种维他命的最小量。请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少。第2行:V个整数(1

2302_78447318的博客 244

xplorer&sup2;资源管理软件

非常好的一个资源管理软件,简单实用,上手很快。

Healthy Holsteins(二进制枚举)

  Healthy HolsteinsBurch &amp; Kolstad Farmer John prides himself on having the healthiest dairy cows in the world. He knows the vitamin content for one scoop of each feed type and the minimum d...

Simone chou... 253

健康管理软件HealthyCare v2.0及源代码

使用C#编写,类似于防沉迷系统,界面没有用一张图片,全靠GDI+程序来绘制的精美界面.集成自定义卡路里计算引擎,导出为XML文件的数据,可以自行添加和设定卡路里数据,方便计算.提示:启动软件后如果不想晚上12点自动关机,请选择nightmode为enable,即夜间模式,启用以后水晶按钮会亮起台灯似的光芒. 晚上看着很美. 版权所有,请勿转载.

P1460 健康的荷斯坦奶牛 Healthy Holsteins(DFS)

题目描述 农民JOHN以拥有世界上最健康的奶牛为傲。他知道每种饲料中所包含的牛所需的最低的维他命量是多少。请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少。 给出牛所需的最低的维他命量,输出喂给牛需要哪些种类的饲料,且所需的饲料剂量最少。 维他命量以整数表示,每种饲料最多只能对牛使用一次,数据保证存在解。 输入输出格式 输入格式: 第1行:一个整数V(1<...

一身清贫怎敢入繁华 1154

The Healthy Programmer

Small changes to your habits can improve your health—without getting in the way of your work. The Healthy Programmer gives you a daily plan of action that’s incremental and iterative just like the software development processes you’re used to. Every tip, trick, and best practice is backed up by the advice of doctors, scientists, therapists, nutritionists, and numerous fitness experts., We’ll review the latest scientific research to understand how being healthy is good for your body and mind. You’ll start by adding a small amount of simple activity to your day—no trips to the gym needed. You’ll learn how to mitigate back pain, carpal tunnel syndrome, headaches, and many other common sources of pain., You’ll also learn how to refactor your diet to properly fuel your body without gaining weight or feeling hungry. Then, you’ll turn the exercises and activities into a pragmatic workout methodology that doesn’t interfere with the demands of your job and may actually improve your cognitive skills., You’ll also learn the secrets of prominent figures in the software community who turned their health around by making diet and exercise changes. Throughout, you’ll track your progress with a companion iPhone app., Finally, you’ll learn how to make your healthy lifestyle pragmatic, attainable, and fun. If you’re going to live well, you should enjoy it.

The Healthy Programmer.pdf

The Healthy Programmer, the people who always sitting down there for a long time must read it, you will benefit a lot.

USACO 2.1.4 Healthy Holsteins

题意: 给奶牛喂营养素,一共有V种维生素需求,然后有G勺喂养(每勺只喂一次),并给出每勺喂养所获得的对应维生素量, 给出至少V种维生素所要达到的需求,求出最少的勺数,如果勺子数相同,勺子编号尽量小 解法: 一共G勺(G<=15),每勺只有0和1两种情况,那么枚举每一种方案,一共2^15种方案 /* ID: lsswxr1 PROG: holstein LANG...

weixin_30246221的博客 180

本地使用大模型:Ollama+open-webui+AnythingLLM(Windows+linux)

随着大模型的发展,大量的开源模型可以被直接使用。大模型的使用可以选择在云端或者在本地,如果本地存储空间尚可,而且模型需求不是很大的话,我们可以选择在本地部署一个大模型来使用。针对特定的任务需求,进一步在本地去微调我们的大模型。我在windows和linux上都尝试了一遍,这里记录一下过程。

wpqgt的博客 2165

usaco 2.1.4 Healthy Holsteins

surprise! 在nnnnnnn久没码代码然后前两天码了一个还出现了本机和上传结果不符的诡异情况后,今天终于rp爆发了.一次编译过+一次提交过,虽然查逻辑错还是花了挺久,大概有三处,不过还是很满意的,而且第一次用位运算,虽然犯了个2,纠结了好久,但总体还是不错的,虽然害的没睡成午觉... Healthy Holsteins Burch & Kolstad Farmer John

shshwdr的专栏 1076

219页华为供应链管理:市场预测S&OP计划、销售预测与存货管理精要

S&OP计划的整合作用:S&OP是一种综合的销售和运营计划流程,它将市场预测、生产能力、库存水平和财务目标整合在一起,以确保企业能够平衡供需,实现最佳的运营效率。持续监控与改进:市场预测、S&OP计划、计划委员会的决策以及存货管理都需要持续的监控和评估。供应链策略与执行:华为ISC拥有清晰的供应链策略,并通过SISC架构实现了策略的有效执行,包括供应链网络设计、库存管理、物流优化等。持续的供应链创新:华为ISC不断探索新的供应链管理方法和技术,如数字化供应链、智能物流等,以适应全球化和市场的快速变化。

zuoan1993的博客 2433

别再只会插拔了!深入Linux内核,手把手调试USB热插拔中断(以高通平台为例)

本文深入探讨了Linux内核中USB热插拔中断的调试方法,特别针对高通平台提供了详细的实战指南。从硬件基础到内核机制,再到中断调试工具和常见问题排查,帮助开发者系统性地解决USB设备识别问题。通过监控中断状态、分析处理流程和高级调试技巧,提升USB热插拔的稳定性和性能。

weixin_29161785的博客 428

Healthy Holsteins(USACO 2.1.4)

暴力枚举,使用bitset优化 bitset在此处用作枚举状态空间 #include #include #include #include using namespace std; #ifdef LOCAL ofstream fout ("out.txt"); ifstream fin ("in.txt"); #else ofstream fout ("holstein.o

SummerorWinter的博客 496

十二、基于FPGA实现slave SelectMAP配置逻辑

slave SelectMAP配置

weixin_41838250的博客 8753

USACO 2.1.4 Healthy Holsteins (DFS)

题意:农民JOHN以拥有世界上最健康的奶牛为傲。他知道每种饲料中所包含的牛所需的最低的维他命量是多少。请你帮助农夫喂养他的牛,以保持它们的健康,使喂给牛的饲料的种数最少。 给出牛所需的最低的维他命量,输出喂给牛需要哪些种类的饲料,且所需的饲料剂量最少。 维他命量以整数表示,每种饲料最多只能对牛使用一次,数据保证存在解。 思路:搜索每种饲料用了没有,即每层搜索有两种状态:vis[n]=0...

Tongqi 785

秃鹰搜索优化算法(BES)详解:从自然捕食到全局优化

秃鹰搜索优化算法(Bald Eagle Search Optimization Algorithm,BES)是由马来西亚学者Alsattar等人于2020年提出的一种新型元启发式优化算法。该算法灵感来源于秃鹰在自然界中高超的捕食行为,特别是其独特的狩猎策略和卓越的视觉搜索能力,模拟了秃鹰捕食鲑鱼等猎物的完整过程。

qq_42212808的博客 1350

地下管网巡检机器人:基于YOLOv8与UI界面的智能化系统设计与实现

通过YOLOv8模型的目标检测功能结合实时视频流,我们能够实现对地下管网巡检机器人的智能化控制。系统通过图像识别技术帮助巡检人员快速识别管道中的各种缺陷和障碍物,从而提高巡检效率和准确性。未来,我们可以继续优化模型,增加更多的目标类别,并通过强化学习等方法提高机器人的自主巡检能力。此外,随着硬件技术的发展,未来的巡检机器人可能会具备更强的感知能力和更高的智能水平。

YOLO 529
上一篇: usaco2.1.3 Sorting a Three-Valued Sequence
下一篇: usaco2.2.4 Party Lamps
max_kibble
博客等级 码龄11年 2粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值