| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6578 人关注过本帖
标题:函数递归调用时汉诺塔问题,大家是怎么学习的?
只看楼主 加入收藏
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
………………这么说,贪婪是肯定过不了了……

改代码去……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-23 11:07
蓝色线段树
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2008-10-18
收藏
得分:0 
[bo][un]StarWing83[/un] 在 2008-10-23 11:07 的发言:[/bo]

………………这么说,贪婪是肯定过不了了……

改代码去……

我都说了不一定啦。。。。
2008-10-23 11:14
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
得分:0 
回复 20# 蓝色线段树 的帖子
啥是8数码问题,解释解释、
2008-10-23 11:18
rootkit
Rank: 1
等 级:新手上路
帖 子:197
专家分:5
注 册:2008-9-26
收藏
得分:0 
瘟38说的我怎么看不懂,难道有比A*还要高效的算法?
如果你的A*效率低,有太多的回溯,就是你估值函数没有设计好。

A General Graph-Searching Algorithm

1. Create search tree Tr consisting only of the start node (root) n0. Put n0 on an ordered list called OPEN.
2. Create empty list called CLOSED.
3. If OPEN is empty, exit with failure.
4. Move the first node from OPEN, called n, to CLOSED.
5. If n is a goal node, exit with success; the solution is the path from n to n0 along the edges in Tr.
6. Expand node n by generating a set M of successors and connect them to n. Also put the members of M on OPEN.
7. Reorder the list OPEN according to a specific rule.
8. Go to step 3.

这是通用搜索模式,在第七步中:
1 如果把新open的节点放在open表前面就是DFS
2 如果把新open的节点放在open表后面就是BFS
3 如果把新open的节点按其h(n)+g(n)值大小按递增序插入open表就是best-first search,也叫A*。

8数码问题的A*算法应该这样设置估值函数:
f’(n) = depth of n in the tree + number of digits in the puzzle in incorrect position.

降妖除魔路,仗剑载酒行
借问谁家子,大唐游侠儿
2008-10-23 11:39
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
蓝色,087654321这组数据你要花多长时间?

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-23 11:50
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
A*是很快,快的原因是智能化的搜索,所以A*和A*本身都是不同的,差别在于估价函数。选择的估价函数的好坏,直接影响到了算法本身的效率。有些题目,选择了巧妙而良好的估价函数甚至可以使算法简化为贪婪或者DP,但A*难也就难在估价函数的选择……

看来书上给出的这个函数并不好,087654321应该有解,但是我算了几分钟还是没有出解……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-23 11:55
蓝色线段树
Rank: 1
等 级:新手上路
帖 子:86
专家分:0
注 册:2008-10-18
收藏
得分:0 
0.4秒
2008-10-23 11:57
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
晕……《计算机算法》给出的16数码解法是面向决策的,《算法艺术》给出的解法是面向状态的……我综合一下再说……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-23 11:59
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
我知道原因了,我没有判断重复到达统一状态的不同路线的f值,所以重复了,算这个解的时候出现了环……

继续Coding……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-23 12:00
rootkit
Rank: 1
等 级:新手上路
帖 子:197
专家分:5
注 册:2008-9-26
收藏
得分:0 
这是两种不同的估值函数选择,区别很明显

For the Eight-puzzle, it seems like a good idea to expand those nodes first that lead to configurations similar to the goal state.
In our first attempt, we will simply define f’ as the number of digits in the puzzle that are not in the correct (goal) position yet.
第一次不大聪明的尝试:
图片附件: 游客没有浏览图片的权限,请 登录注册

You see that with this simple function f’ the algorithm is still likely to perform unnecessarily many steps.
We should increase the “cost” of searches in greater depth to make the algorithm avoid them.
To achieve this, we simply add the current depth of a node to its f’-value.
Now f’(n) = depth of n in the tree + number of digits in the puzzle in incorrect position.
Let us try again!
明智的选择:
图片附件: 游客没有浏览图片的权限,请 登录注册

降妖除魔路,仗剑载酒行
借问谁家子,大唐游侠儿
2008-10-23 12:01
快速回复:函数递归调用时汉诺塔问题,大家是怎么学习的?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018034 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved