找回密码
 欢迎注册
查看: 14402|回复: 3

[提问] project euler问题367

[复制链接]
发表于 2012-1-22 23:12:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
Problem 367
14 January 2012


Bozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence is sorted and if not swapping randomly two elements. This is repeated until eventually the sequence is sorted.

If we consider all permutations of the first 4 natural numbers as input the expectation value of the number of swaps, averaged over all 4! input sequences is 24.75.
The already sorted sequence takes 0 steps.

In this problem we consider the following variant on bozo sort.
If the sequence is not in order we pick three elements at random and shuffle these three elements randomly.
All 3!=6 permutations of those three elements are equally likely.
The already sorted sequence will take 0 steps.
If we consider all permutations of the first 4 natural numbers as input the expectation value of the number of shuffles, averaged over all 4! input sequences is 27.5.
Consider as input sequences the permutations of the first 11 natural numbers.
Averaged over all 11! input sequences, what is the expected number of shuffles this sorting algorithm will perform?

Give your answer rounded to the nearest integer.


“挑2和交换”24.75和“挑3和洗牌”27.5怎么推导?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2012-1-22 23:13:36 | 显示全部楼层
既然有可能无限循环,那么任何数+无穷的平均数是无穷
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-1-24 17:13:09 | 显示全部楼层
project euler 362 你是咋解的啊
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2012-1-25 18:33:41 | 显示全部楼层
4!的状态还是很好处理的。而目标状态是什么并不重要,任意一个结果都相同。
而不同状态之间的转移概率可以构成一个n!对称稀疏阵A.可以将对称阵中目标状态对应的行和列删除,得到(n!-1)阶矩阵B.b为全1的向量,于是方程
(I-B)x=b
的解就对应各个状态到达目标状态的平均次数。于是解的所有分量的和除以n!就是结果了。
而当n=11时,状态数目达到40M,幸好矩阵是稀疏矩阵,储存还不是问题,但是求解应该要使用迭代法,这里应该可以使用雅可比迭代法,只是不知道收敛速度如何
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-5-18 22:20 , Processed in 0.042326 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表