Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤ 20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long board just long enough to saw into the N planks (i.e., whose length is the sum of the lengths Li). FJ is ignoring the "kerf", the extra length lost to sawdust when a sawcut is made; you should ignore it, too.
FJ sadly realizes that he doesn’t own a saw with which to cut the wood, so he mosies over to Farmer Don’s Farm with this long board and politely asks if he may borrow a saw.
Farmer Don, a closet capitalist, doesn’t lend FJ a saw but instead offers to charge Farmer John for each of the N-1 cuts in the plank

本文介绍了一个关于农夫John如何在有限成本下将一块长木板锯成若干指定长度的小木板的问题。农民Don会按每块木板的长度收取锯木费用。通过使用类似Huffman编码的策略,选择每次锯取最短的木板以减少总费用。文章探讨了如何设计算法来确定最低成本的锯木方案。
最低0.47元/天 解锁文章
2573

被折叠的 条评论
为什么被折叠?



