usaco5.3.1 Milk Measuring

手把手教你用smarteye搭建免费GB28181监控平台(含海康设备接入避坑指南) 本文提供了一份基于SmartEye搭建免费GB28181视频监控平台的实战指南。详细介绍了从服务器部署、GB28181协议核心配置,到海康威视等主流设备接入的完整流程,并重点分享了设备注册失败、无法预览等常见问题的深度排错方法,旨在帮助中小企业及开发者低成本实现多品牌监控设备的统一管理。 阅读详情

一 原题

Milk Measuring
Hal Burch

Farmer John must measure Q (1 <= Q <= 20,000) quarts of his finest milk and deliver it in one big bottle to a customer. He fills that bottle with exactly the number of quarts that the customer orders.

Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quarts of milk from his giant milk tank. Since the pails each cost the same amount, your task is to figure out a minimal set of pails Farmer John can purchase in order to fill a bottle with exactly Q quarts of milk. Additionally, since Farmer John has to carry the pails home, given two minimal sets of pails he should choose the "smaller" one as follows: Sort the sets in ascending order. Compare the first pail in each set and choose the set with the smallest pail. If the first pails match, compare the second pails and choose from among those, else continue until the two sets differ. Thus the set {3, 5, 7, 100} should be chosen over {3, 6, 7, 8}.

To measure out milk, FJ may completely fill a pail from the tank and pour it into the bottle. He can never remove milk from the bottle or pour milk anywhere except into the bottle. With a one-quart pail, FJ would need only one pail to create any number of quarts in a bottle. Other pail combinations are not so convenient.

Determine the optimally small number of pails to purchase, given the guarantee that at least one solution is possible for all contest input data.

PROGRAM NAME: milk4

INPUT FORMAT

Line 1:The single integer Q
Line 2:A single integer P (1 <= P <= 100) which is the number of pails in the store
Lines 3..P+2:Each line contains a single integer pail_value (1 <= pail_value <= 10000), the number of quarts a pail holds

SAMPLE INPUT (file milk4.in)

16
3
3
5
7

OUTPUT FORMAT

The output is a single line of space separated integers that contains:

  • the minimum number of pails required to measure out the desired number of quarts, followed by:
  • a sorted list (from smallest to largest) of the capacity of each of the required pails

SAMPLE OUTPUT (file milk4.out)

2 3 5


二 分析

完全背包,不过需要从一个大集合中选定使用哪些元素作为背包集合。使用迭代加深的方法枚举背包集合,对于一个背包集合,DP判断是否可行。


三 代码

运行结果:

USER: Qi Shen [maxkibb3]
TASK: milk4
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.011 secs, 4204 KB]
   Test 2: TEST OK [0.000 secs, 4204 KB]
   Test 3: TEST OK [0.000 secs, 4204 KB]
   Test 4: TEST OK [0.000 secs, 4204 KB]
   Test 5: TEST OK [0.000 secs, 4204 KB]
   Test 6: TEST OK [0.000 secs, 4204 KB]
   Test 7: TEST OK [0.205 secs, 4204 KB]
   Test 8: TEST OK [0.130 secs, 4204 KB]
   Test 9: TEST OK [0.054 secs, 4204 KB]
   Test 10: TEST OK [0.497 secs, 4204 KB]

All tests OK.

YOUR PROGRAM ('milk4') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.


AC代码:

/*
ID:maxkibb3
LANG:C++
PROB:milk4
*/

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXQ = 20005;
const int MAXP = 105;

int Q, P;
int C[MAXP];
vector<int> Ans;
bool Vis[MAXP];
bool Dp[MAXQ];

void init() {
    scanf("%d%d", &Q, &P);
    for(int i = 0; i < P; i++)
        scanf("%d", &C[i]);
    sort(C, C + P);
}

bool check() {
    memset(Dp, 0, sizeof(Dp));
    int s = 0, ssize = Ans.size();
    for(int i = 0; i < ssize; i++)
        s += Ans[i];
    if(s > Q) return false;
    Dp[s] = true;
    for(int i = s + 1; i <= Q; i++) {
        for(int j = 0; j < ssize; j++) {
            Dp[i] = Dp[i] || Dp[i - Ans[j]];
            if(Dp[i]) break;
        }
    }
    return Dp[Q];
}

bool dfsid(int _num) {
    if(_num == 0) {
        bool ret = check();
        if(ret) {
            printf("%d", (int)Ans.size());
            for(int i = 0; i < Ans.size(); i++)
                printf(" %d", Ans[i]);
            printf("\n");
        }
        return ret;
    }
    for(int i = 0; i < P; i++) {
        if(Vis[i]) continue;
        Vis[i] = true;
        Ans.push_back(C[i]);
        if(dfsid(_num - 1)) return true;
        Ans.pop_back();
        Vis[i] = false;
    }
    return false;
}

void solve() {
    for(int i = 1; i <= P; i++) {
        memset(Vis, 0, sizeof(Vis));
        if(dfsid(i)) break;
    }
}

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


解读文献(五)------基于阻抗控制 文章目录背景主动柔顺控制阻抗控制基于力的阻抗控制基于位置的阻抗控制力位混合控制 背景 主动柔顺控制 阻抗控制 基于力的阻抗控制 基于位置的阻抗控制 力位混合控制 ... 阅读详情

相关推荐

Jetson编译安装pycuda

可使用nvcc --version查看是否有信息输出,若没有,且安装cuda的情况下,需要手动将CUDA 的路径添加到环境变量中。编译生成_pvt_struct.cpython-38-aarch64-linux-gnu.so文件。基于jetson orin nano jetpack512模块上安装pycuda。4、获取pycuda源码(版本根据实际情况获取)2、进入conda环境并安装cuda工具包。9、若未检测出来需要清除并强制编译。7、编译成功后安装pycuda。5、配置编译并设置环境变量。

qq_48175141的博客 972

C++——【USACO 5.3.1】——Milk Measuring

Milk Measuring Hal Burch Farmer John must measure Q (1 Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quart

McDonnell_Douglas的博客 713

新手避坑指南:在MacBook上为PyTorch正确配置MPS环境,跑通第一个YOLOv8训练

本文详细指导新手如何在MacBook上为PyTorch正确配置MPS环境,并成功运行YOLOv8训练。从环境准备、PyTorch安装到YOLOv8配置和性能调优,提供全面的避坑指南和实用技巧,帮助开发者充分利用Mac的GPU加速能力。

weixin_29100399的博客 228

[usaco]5.3.2 Milk Measuring 动态规划

Milk Measuring Hal Burch Farmer John must measure Q (1 <= Q <= 20,000) quarts of his finest milk and deliver it in one big bottle to a cu

马云雷的专栏 1015

VGA系列之一:VGA显示网络图片

VGA系列之一:VGA显示网络图片VGA系列之一VGA显示网络图片 1 如何用FPGA实现VGA显示 2 网络图片和VGA显示有何区别 3VGA如何显示图片

善良の一休君的博客 1万+

Light Tools 8.4 在 win10系统上的安装方法(64位)

** 总的来说安装LT需要以下步骤(折腾了三天终于装好): 安装LT软件–禁用签名–加载含数字签名的第三方inf–添加注册表/安装驱动/添加密钥–成功破解 一、下载对应的LightTools 8.4版本软件,如下图为解压后的文件: 并选择 进行默认安装。 二、禁用数字签名。这里我用了两种方法,一种不行就换另一种,最终成功禁用。 方法1: 1、输入“cmd”并以管理员身份运行; 2、输入或复制 bcdedit.exe /set nointegritychecks on (此命令若没成功,再试bcded

weixin_45560953的博客 1万+

USACO Section 5.3 Milk Measuring (IDDFS+dp)

迭代加深搜索,从小到大枚举桶数的上限maxd:对每个maxd,枚举每个组合,判断是否能够倒出q;直到得到answer。判断的部分就用dp(完全背包)。-------------------------------------------------------------------------#include<cstdio>#include<iostream>#inclu...

weixin_30906701的博客 200

UA-DETRAC数据集转YOLO格式

UA-DETRAC转YOLO

lafsca5的博客 9107

USACO 5.3 Milk Measuring

Milk MeasuringHal Burch Farmer John must measure Q (1 <= Q <= 20,000) quarts of his finest milk and deliver it in one big bottle to a customer. He fills that bottle with exactly the number...

weixin_30539835的博客 178

【密码学】生成8位26个字母和数字的全排列(密码字典,密钥)c++代码(非递归高效直接)

生成8位26个字母和数字的全排列(密钥)代码(非递归高效直接) 用C语言或C++,生成一个8位的26个字母和数字的全排列的原代码,例如从:00000000到ZZZZZZZZ。 说明:生成的这个字典会非常大,有36^8条记录,估计要3T的硬盘,跑一个晚上看看         这个方法比递归更高效,更直接。                                                ...

Wu_Being 的优快云 博客 1万+

AMD机密计算虚拟机介绍

AMD机密计算虚拟机介绍

木简熙的博客 524

Milk Measurement

Milk Measurement 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Each of Farmer John’s cows initially produces G gallons of milk per day (1≤G≤109). Since the milk output of a cow is known to potentially change ov...

ACM2017 968

【AI智能体】Codex 生成高质量电商套图实战操作详解

Codex 生成高质量电商套图实战操作详解

congge 4524

usaco training 5.3.1 Milk Measuring 题解

【原题】    Milk Measuring Hal Burch Farmer John must measure Q (1 Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure o

阿蒋的专栏 2154

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Milk Measuring (milk4)[USACO 5.3.1]

算法:DP+搜索 分析:解决这到题的思路还是比较清晰的。       先快排一下,保证集合最小,再从集合的规模上面先从小到大枚举一下,然后利用DFS选出组成牛奶的箱子种类,最后用选出来的箱子种类做一次完全背包,如果能组成牛奶量,那么它一定是最优的。 { ID:10

292

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

USACO5.3.1 Milk Measuring (milk4)

用dfsid枚举每一种取法,然后用完全背包判断是否符合题意。 不会超时。/* TASK:milk4 ID:shijiey1 LANG:C++ */ #include #include #include #include #include using namespace std; int m, n; int arr[105]; set pail; int min(int a, int

Shion的专栏 563

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

USACO Milk Measuring 解题报告

这道题我是用一个数组记录每个 q (1~Q)的最好组成。

thestoryofsnow的专栏 601

洛谷P2744 [USACO5.3]量取牛奶Milk Measuring

题目描述农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最好的牛奶,并把它装入一个大瓶子中卖出。消费者要多少,他就给多少,从不有任何误差。农夫约翰总是很节约。他现在在奶牛五金商店购买一些桶,用来从他的巨大的牛奶池中量出 Q 夸脱的牛奶。每个桶的价格一样。你的任务是计算出一个农夫约翰可以购买的最少的桶的集合,使得能够刚好用这些桶量出 Q 夸脱的

yanshannan的博客 338

[USACO5.3]量取牛奶Milk Measuring

https://daniu.luogu.org/problemnew/show/P2744 滚动数组压去第一维:前i种木桶 f[j] 量取体积j最少需要几种木桶 g[j] 体积j的最优解是否使用了第i种木桶 f[j]= f[j-a[i]] + g[j-a[i]]^1 输出方案时用搜索,DP检验 g[j] 表示用当前搜索的木桶方案,能否量取体积j g[j]|=g[j-a...

weixin_30462049的博客 217

爆搜小议-洛谷2744[USACO5.3]量取牛奶Milk Measuring

我一开始用dp做的,后来发现好像子状态的最优解未必能构成最终答案的最优解,挣扎一会就放弃了; 后来去看看别人的题解,发现是爆搜; 爆搜啊……. 于是就爆搜了,却还是超时; 我和别人的程序对拍一下,发现大同小异,但细节决定成败,小异像大坝的蚁穴,把我程序打垮了; 现在想想preyer的劝告: 前两题一定要AC,后两题分分必争! 是极其正确的啊#include<iostream> #inc

我怎么这么菜的呢 564

洛谷 P2744 [USACO5.3]量取牛奶Milk Measuring

P2744 [USACO5.3]量取牛奶Milk Measuring 题目描述 农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最好的牛奶,并把它装入一个大瓶子中卖出。消费者要多少,他就给多少,从不有任何误差。 农夫约翰总是很节约。他现在在奶牛五金商店购买一些桶,用来从他的巨大的牛...

HJ921004的博客 258

USACO 5.3 章节

相关讲解可在USACO上看原文,也可以搜索nocow找到翻译的! (nocow上有些微翻译是有问题的,如果想看nocow翻译的建议也对着英文看) 以下记录以下 自己之前未掌握的一些要点,以及按自己的括号表述的形式来记录。 USACO Section 5.3 启发式搜索 启发式搜索的主要思想是通过评价一个状态有"多好"来改进对于解的搜索. 0<= 可行的估价函数 <= 实际代价 启发式...

weixin_30745641的博客 383

usaco 5.3 Milk Measuring(背包)

Milk Measuring Hal Burch Farmer John must measure Q (1 Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quarts

志当存高远 888

USACO SECTION 5.3 Milk Measuring

Milk Measuring Hal Burch Farmer John must measure Q (1 Farmer John has always been frugal. He is at the cow hardware store where he must purchase a set of pails with which to measure out Q quarts

401

Usaco Training Section 5.3 Milk Measuring

有n种牛奶,问最少取多少种牛奶,使能组成q升,并输出最小的一组解。(牛奶只能加,不能减) 宽搜会mle,所以直接id搜索。 枚举取k种牛奶,然后dfs+check(dp) #include&lt;bits/stdc++.h&gt; #define ll long long #define ull unsigned long long #define inf 2147483647 #de...

Monster的博客 241

Milk Measuring_usaco 5.3_dfsid

Description  农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最好的牛奶,并把它装入一个大瓶子中卖出。消费者要多少,他就给多少,从不有任何误差。   农夫约翰总是很节约。他现在在奶牛五金商店购买一些桶,用来从他的巨大的牛奶池中量出 Q 夸脱的牛奶。每个桶的价格一样。你的任务是计算出一个农夫约翰可以购买的最少的桶的集合,使得能够

olahiuj的博客 405
上一篇: usaco5.1.3 Musical Themes
下一篇: usaco5.3.2 Window Area
max_kibble
博客等级 码龄11年 2粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值