浅谈砝码称重问题的两种算法 - atlantis press
International Conference on Education, Management and Computer Science (ICEMC 2016)
Two Algorithms for Weight Problems
1, a 1 1, b 1 1
Chun Shi , Xin Yin , Chunyu Li , Ruyin Xu and Shuqian He
1Lab. Digital Medium, School of Information Science & Technology, Hainan Normal University,
Haikou, Hainan 571127, China
abyshichun@, blichunyu_hn@126.com
Keywords: Weight problem; Greedy algorithm; Dynamic programming; C++
Abstract. Research on weight problem is helpful to solve other problems, and it has practical
significance for the design of the algorithm and the solution of the real life. The purpose of this
paper is to introduce the solution for the weight problem with both greedy algorithm and dynamic
programming. We mainly discuss the difference between these two algorithms based on different
solution methods. The algorithms in this paper are described in C language, natural language or
charts.
浅谈砝码称重问题的两种算法
1,a 1 1,b 1 1
石春 ,尹鑫 ,李春雨 ,许茹茵 ,何书前
1.海南师范大学 信息科学技术学院,海南 海口 571127
a b
shichun@, lichunyu_hn@126.com
摘要:砝码称重问题的研究有助于解决其它各种拓展出的问题,对算法设计和实际生活中问题
的解决都具有现实的意义。对砝码称重问题,用贪心算法与动态规划两种方法求解。从求解
思路介绍两种算法的差异。算法使用C 语言,自然语言以及图表描述。
关键词:称重问题; 贪心算法; 动态规划; C++
1. 引言
在算法学习和研究过程中,针对同一个问题,采用不同的算法进行分析,可以有效加深对算
法特征的理解,同时也为解决其他问题开拓了更广阔的思路[1][2]。
砝码称重是算法分析中一个经典的问题,已经有学者从多个方面进行了探讨[2][3][4],本文
尝试从贪心算法[5][6]和动态规划[7][8]给出算法解决方案之间的差异。
2. 砝码称重的问题描述
设有1g,2g,5g 的砝码各若干枚。试设计算法,计算可用这些砝码称出多少种不同的重量。
例如,有 1g,2g,5g 的砝码各1 枚,则可用它们称出 1g,2g,3g,5g,6g,7g,8g 共7 种
不同的