这里有一道测试题

来源:百度知道 编辑:UC知道 时间:2024/05/28 21:13:47
There is a big tiger and a small one,a big wolf and a small one,a big fox and a small one.They need to go across a river.
There is a small boat which can bear at most two animals once,and the small one can't leave the big one.
Question: How do they go across the river?
The little one can move the boat by itself.

呵,终于有时间想问题了,我找了相关的资料,意大利数学家(塔尔塔利亚)提了个过河问题。问题是这样的:三个漂亮的新娘和他们的新郎要过河。可是小船只能装载两人。为了避免任何不良情况,过河必须这样安排:除非是自己的丈夫,任何一位新娘不得和别人的丈夫独处。在新娘和新郎都会划船的情况下,该如何安排过河呢?
给你答案,你自己把模型套进就行了,而且你增加人数或别的,很容易设计出更复杂的问题。
答案:设新娘为W,新郎为H,则有H1,W1;H2,W2;H3,W3;分九步,1:H1和W1过河,2:W1返回,3:W1,W2过河,4:W2返回,5:H2和W2过河,(你学过递归的话,接下来用递归就可以了)6:W2返回,7:W2,W3过,8:W3返回,9:H3,W3过河。过河完毕。