| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
网上找到一个很好的方法.In Reply To:应该用什么HASH函数判重. Posted by:zhaokkk27 at 2007-09-14 19:13:56 这里的哈希函数是用能对许多全排列问题适用的方法。取n!为基数,状态第n位的逆序值为哈希值第n位数。对于空格,取其(9-位置)再乘以8!。例如,1 3 7 2 4 6 8 5 8 的哈希值等于: 0*0! + 0*1! + 0*2! + 2*3! + 1*4! + 1*5! + 0*6! + 3*7! + (9-8)*8! = 55596 <9! 具体的原因可以去查查一些数学书,其中1 2 3 4 5 6 7 8 9 的哈希值是0 最小,8 7 6 5 4 3 2 1 0 的哈希值是(9!-1)最大,而其他值都在0 到 (9!-1) 中,且均唯一。 摘自原文的Q4: http://cache.baidu.com/c?word=%B0%CB%CA%FD%3B%C2%EB%2C%C4%E6%D0%F2&url=http%3A//www%2Ecnblogs%2Ecom/wingy/archive/2006/12/07/585879%2Ehtml&p=9a3ed316d9c243dd1ebd9b7a594e&user=baidu Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator