算了一下,发现是不相等的,如果n知道是可以算得出来看
-- t-sql代码
create table tx(x int,y int ,id int);insert into tx select 0,1,1 union all --上select 1,0,2 union all --右 select 0,-1,3 union all --下select -1,0,4; --左
create table t(id int identity(1,1),x int ,y int,pid int);
-- 1.初始insert into t select 0,1,null union all select 1,0,null union all select 0,-1,nullunion all select -1,0,null
-- 2.其它
declare
@i int=1;declare
@n int=3; --declare
@num1 int=0;declare
@num2 int=4;declare
@t table(id int);
while @i<2*@nbegininsert into t select u.x+v.x,u.y+v.y,v.id from t u cross join tx vwhere u.id between
@num1 and @num2;select @num1=min(id),@num2=MAX(id) from t where id>@num2;set @i=@i+1;endselect * from t order by pid --查看所有情况
-- 清理truncate table t;
-- 计算概率select SUM(case when x=0 and y=0 then 1 else 0 end)*1.0/COUNT(1) from t -- 当n=1时 也就是走2步-- 0.200000000000-- 当n=2时 也就是走4步的时候-- 0.117647058823-- 当n=3时 也就是走6步的情况-- 0.080586080586