在算法课程中,我们接触的第一个算法,也是相对简单的算法就是穷举法。其实穷举法的思想是,我们在解决问题时,先确定问题域,通过测试每一个情况,直到我们找到我们想要的答案。
执行结果如下:
There are different methods for TOM to distribute his book to A,B,C
(1,2,3) (1,2,4) (1,2,5) (1,3,2) (1,3,4) (1,3,5) (1,4,2) (1,4,3) (1,4,5) (1,5,2) (1,5,3) (1,5,4) (2,1,3) (2,1,4) (2,1,5) (2,3,1) (2,3,4) (2,3,5) (2,4,1) (2,4,3) (2,4,5) (2,5,1) (2,5,3) (2,5,4) (3,1,2) (3,1,4) (3,1,5) (3,2,1) (3,2,4) (3,2,5) (3,4,1) (3,4,2) (3,4,5) (3,5,1) (3,5,2) (3,5,4) (4,1,2) (4,1,3) (4,1,5) (4,2,1) (4,2,3) (4,2,5) (4,3,1) (4,3,2) (4,3,5) (4,5,1) (4,5,2) (4,5,3) (5,1,2) (5,1,3) (5,1,4) (5,2,1) (5,2,3) (5,2,4) (5,3,1) (5,3,2) (5,3,4) (5,4,1) (5,4,2) (5,4,3)