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 |
Re:打表,很邪恶...In Reply To:Re:打表,很邪恶... Posted by:gongshaoqing at 2009-08-09 20:12:16 var rec:array[1..2,1..12]of longint; n,i:longint; function opt(x,y:longint):longint; var i,ans,temp:longint; begin if rec[x,y]<>-1 then exit(rec[x,y]); if y=0 then ans:=0 else if x=1 then if y=1 then ans:=1 else ans:=opt(1,y-1)*2+1 else begin ans:=2*opt(2,y-1)+1; for i:=1 to y-2 do begin temp:=2*(opt(2,i)+opt(1,y-i-1))+1; if temp<ans then ans:=temp; end; end; rec[x,y]:=ans; opt:=ans; end; begin assign(input,'hanoi.in'); reset(input); assign(output,'hanoi.out'); rewrite(output); n:=12; fillchar(rec,sizeof(rec),$FF); for i:=1 to n do writeln(opt(2,i)); close(input); close(output); end. ...我寂寞地交记忆化 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator