USACO Section 5.3 Milk Measuring (IDDFS+dp)

迭代加深搜索,从小到大枚举桶数的上限maxd:对每个maxd,枚举每个组合,判断是否能够倒出q;直到得到answer。判断的部分就用dp(完全背包)。
-------------------------------------------------------------------------
-------------------------------------------------------------------------
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
USACO Section 5.3 Milk Measuring (IDDFS+dp)的更多相关文章
- USACO 5.3 Milk Measuring
Milk MeasuringHal Burch Farmer John must measure Q (1 <= Q <= 20,000) quarts of his finest mil ...
- USACO Section 5.3 Big Barn(dp)
USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1 (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...
- 洛谷 P2744 [USACO5.3]量取牛奶Milk Measuring
P2744 [USACO5.3]量取牛奶Milk Measuring 题目描述 农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最 ...
- luogu P2744 [USACO5.3]量取牛奶Milk Measuring
题目描述 农夫约翰要量取 Q(1 <= Q <= 20,000)夸脱(夸脱,quarts,容积单位——译者注) 他的最好的牛奶,并把它装入一个大瓶子中卖出.消费者要多少,他就给多少,从不有 ...
- [USACO Section 5.3]量取牛奶 Milk Measuring (动态规划,背包$dp$)
题目链接 Solution 完全背包 \(dp\) , 同时再加一个数组 \(v[i][j]\) 记录当总和为\(j\) 时第 \(i\) 种物品是否被选. 为保证从小到大和字典序,先将瓶子按大小排序 ...
- USACO Section 1.3 Mixing Milk 解题报告
题目 题目描述 Merry Milk Makers 公司的业务是销售牛奶.它从农夫那里收购N单位的牛奶,然后销售出去.现在有M个农夫,每个农夫都存有一定量的牛奶,而且每个农夫都会有自己的定价.假设所有 ...
- USACO Section 1.4 Mother's Milk 解题报告
题目 题目描述 有三个牛奶桶,三个桶的容积分别是A,B,C,最小为1,最大为20.刚开始只有第三个桶里面装满了牛奶,其余两个桶都是空的.我们现在可以将第三个桶中的牛奶往其他两个桶里面倒一些牛奶,然后还 ...
- [USACO5.3]量取牛奶Milk Measuring
https://daniu.luogu.org/problemnew/show/P2744 滚动数组压去第一维:前i种木桶 f[j] 量取体积j最少需要几种木桶 g[j] 体积j的最优解是否使用了第 ...
- 【USACO 2.3】Money Systems(dp)
v种货币,求有多少种组成和为n. dp[i][j]表示前i种货币价格为j有多少种方案,dp[i][j]+=dp[i-1][j-c]. http://train.usaco.org/usacoprob2 ...
随机推荐
- linux内核参数调优,缓冲区调整,tcp/udp连接管理,保持,释放优化,gossary,terms
changing a readonly file (linu single user mode)
- leetcode_question_85 Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- 修改spinner选中以后显示的字体颜色
原来spinner选中以后显示的view 还是textview ,这样就是可以设置它的字体颜色了 sp.setOnItemSelectedListener(new OnItemSelectedLi ...
- PHP 魔术方法之__set__get__unset,__isset,__call
<?php /*** 魔术方法: 是指某些情况下,会自动调用的方法,称为魔术方法 PHP面向对象中,提供了这几个魔术方法, 他们的特点 都是以双下划线__开头的 __construct(), _ ...
- sass的cd进入目录
今天在弄sass安装进入项目文件命令 直接f:
- Pat(Advanced Level)Practice--1043(Is It a Binary Search Tree)
Pat1043代码 题目描写叙述: A Binary Search Tree (BST) is recursively defined as a binary tree which has the f ...
- HTML系列(二):头部meta元素
有关name: 一.页面关键字 网站关键字:用户通过搜索引擎能搜到该网站的词汇.最好控制在10个以内. 基本语法: <meta name="keywords" content ...
- Spring MVC详细示例实战教程【转】
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...
- select实现选中跳转
select选择后直接跳转到其他网站的三种方式 第一种: ************************** <html> <head> <meta http- ...
- Hadoop 架构初探
对流行Hadoop做了一些最基本的了解,暂时没太大感觉,恩先记点笔记吧. = = Hadoop 基本命令及环境安装 一.下载虚拟机镜像 目前比较流行的有以下三个: (CHD) http://www.c ...