RQ254 占内存的递归函数
模拟就好了,不过要注意顺序....
type int=longint; var m : array[0..20,0..20,0..20] of boolean; f : array[0..20,0..20,0..20] of longint; a,b,c : longint; function get(a,b,c:longint):longint; begin if m[a,b,c] then exit (f[a,b,c]); if (a<=0) or (b<=0) or (c<=0) then exit(1); if (a>20)or(b>20)or(c>20) then exit(get(20,20,20)); if (a<b) and (b<c) then begin f[a,b,c]:=get(a-1,b,c)+get(a-1,b-1,c)+get(a-1,b,c-1)-get(a-1,b-1,c-1); m[a,b,c]:=true; exit(f[a,b,c]); end; f[a,b,c]:=get(a-1,b,c)+get(a-1,b-1,c)+get(a-1,b,c-1)-get(a-1,b-1,c-1); m[a,b,c]:=true; exit(f[a,b,c]); end; begin readln(a,b,c); writeln('w(',a,', ',b,', ',c,') = ', get(a,b,c)); readln(a,b,c); while not((a=-1)and(b=-1)and(c=-1)) do begin writeln('w(',a,', ',b,', ',c,') = ',get(a,b,c)); readln(a,b,c); end; end.