讨论 / 为什么我递归打表 却错了??
what? 2010-11-09 21:03:00
点我顶贴 收藏 删除
procedure f(k,r:longint);

begin

if k=m then

begin

if r=1 then

inc(x);

exit;

end;

f(k+1,t[r]);

f(k+1,s[r]);

end;

for i:=1 to n-1 do

s[i]:=i+1;

s[n]:=1;

for i:=2 to n do

t[i]:=i-1;

t[1]:=n;

f(0,1);

我的递归有问题??

if (m=30)and(n=4) then write(536870912);

#1 what?@2010-11-07 02:22:00
回复 删除
质疑数据。。

。。

#2 what?@2010-11-07 02:22:00
回复 删除
质疑数据。。

。。

#3 what?@2010-11-07 02:37:00
回复 删除
我错了。。。

原来我递归没问题

要分的回复

#4 what?@2010-11-07 02:37:00
回复 删除
暴力打表 运行了10MIN。。。。。。。

if (m=25)and(n=3) then write(11184810);

if (m=26)and(n=3) then write(22369622);

if (m=27)and(n=3) then write(44739242);

if (m=28)and(n=3) then write(89478486);

if (m=29)and(n=3) then write(178956970);

if (m=30)and(n=3) then write(357913942);

if (m=25)and(n=4) then write(0);

if (m=26)and(n=4) then write(33554432);

if (m=27)and(n=4) then write(0);

if (m=28)and(n=4) then write(134217728);

if (m=29)and(n=4) then write(0);

if (m=30)and(n=4) then write(536870912);

if (m=25)and(n=5) then write(6643782);

if (m=26)and(n=5) then write(13530350);

if (m=27)and(n=5) then write(26667864);

if (m=28)and(n=5) then write(53971350);

if (m=29)and(n=5) then write(106914242);

if (m=30)and(n=5) then write(215492564);

if (m=25)and(n=6) then write(0);

if (m=26)and(n=6) then write(22369622);

if (m=27)and(n=6) then write(0);

if (m=28)and(n=6) then write(89478486);

if (m=29)and(n=6) then write(0);

if (m=30)and(n=6) then write(357913942);

if (m=25)and(n=7) then write(4086550);

if (m=26)and(n=7) then write(10861060);

if (m=27)and(n=7) then write(16878420);

if (m=28)and(n=7) then write(42484682);

if (m=29)and(n=7) then write(69242082);

if (m=30)and(n=7) then write(166823430);

if (m=25)and(n=8) then write(0);

if (m=26)and(n=8) then write(16781312);

if (m=27)and(n=8) then write(0);

if (m=28)and(n=8) then write(67117056);

if (m=29)and(n=8) then write(0);

if (m=30)and(n=8) then write(268451840);

if (m=25)and(n=9) then write(2163150);

if (m=26)and(n=9) then write(10430500);

if (m=27)and(n=9) then write(9373652);

if (m=28)and(n=9) then write(40313160);

if (m=29)and(n=9) then write(40060078);

if (m=30)and(n=9) then write(156305070);

if (m=25)and(n=10) then write(0);

if (m=26)and(n=10) then write(13530350);

if (m=27)and(n=10) then write(0);

if (m=28)and(n=10) then write(53971350);

if (m=29)and(n=10) then write(0);

if (m=30)and(n=10) then write(215492564);

if (m=25)and(n=11) then write(961400);

if (m=26)and(n=11) then write(10401250);

if (m=27)and(n=11) then write(4440150);

if (m=28)and(n=11) then write(40123152);

if (m=29)and(n=11) then write(20030010);

if (m=30)and(n=11) then write(155172330);

if (m=25)and(n=12) then write(0);

if (m=26)and(n=12) then write(11716252);

if (m=27)and(n=12) then write(0);

if (m=28)and(n=12) then write(46333566);

if (m=29)and(n=12) then write(0);

if (m=30)and(n=12) then write(183739940);

if (m=25)and(n=13) then write(354200);

if (m=26)and(n=13) then write(10400602);

if (m=27)and(n=13) then write(1776060);

if (m=28)and(n=13) then write(40116656);

if (m=29)and(n=13) then write(8584290);

if (m=30)and(n=13) then write(155118390);

if (m=25)and(n=14) then write(0);

if (m=26)and(n=14) then write(10861060);

if (m=27)and(n=14) then write(0);

if (m=28)and(n=14) then write(42484682);

if (m=29)and(n=14) then write(0);

if (m=30)and(n=14) then write(166823430);

if (m=25)and(n=15) then write(106260);

if (m=26)and(n=15) then write(10400600);

if (m=27)and(n=15) then write(592020);

if (m=28)and(n=15) then write(40116600);

if (m=29)and(n=15) then write(3121560);

if (m=30)and(n=15) then write(155117522);

#5 what?@2010-11-09 05:14:00
回复 删除
要分的回复

rt

#6 中华武神@2010-11-09 05:16:00
回复 删除
这是哪一题。。。。。
#7 L.Lawliet@2010-11-09 20:27:00
回复 删除
直接DP

const maxn=30;

var f:array[0..maxn,0..maxn]of longint;

i,j,k,m,n:longint;

begin

readln(n,m);

fillchar(f,sizeof(f),0);

f[2,1]:=1;f[n,1]:=1;

for j:=2 to m do

for i:=1 to n do

begin

if i=1 then f[i,j]:=f[n,j-1]+f[2,j-1];

if i=n then f[i,j]:=f[1,j-1]+f[n-1,j-1];

if (i<>1)and(i<>n) then f[i,j]:=f[i-1,j-1]+f[i+1,j-1];

end;

writeln(f[1,m]);

end.

#8 L.Lawliet@2010-11-09 21:03:00
回复 删除
求分。

RT

#9 沧海一声喵@2018-02-08 05:04:22
回复 删除
回复 #8 L.Lawliet:牛逼牛逼!
查看更多回复
提交回复