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 |
HELP!!!!!!!为什么我的程序总是超时,有没有什么好方法剪枝?program p1187; var l1,l2,l3,d:integer; f,p,q1,q2:array[0..10,0..10,0..10,0..30] of longint; procedure main; var i1,i2,i3,temp,j1,j2,j3,temp1:integer; begin p[0,0,0,0]:=1; for i1:=0 to l1 do for i2:=0 to l2 do for i3:=0 to l3 do for temp:=1 to d do if temp<i1+i2+i3 then begin if i3<>0 then f[i1,i2,i3,temp]:=p[i1,i2,i3-1,temp-1] else if i2<>0 then f[i1,i2,i3,temp]:=p[i1,i2-1,i3,temp-1] else if i1<>0 then f[i1,i2,i3,temp]:=p[i1-1,i2,i3,temp-1]; p[i1,i2,i3,temp]:=f[i1,i2,i3,temp]; for j1:=0 to i1 do for j2:=0 to i2 do for j3:=0 to i3 do p[i1,i2,i3,temp]:=(p[i1,i2,i3,temp]+f[j1,j2,j3,temp]*q2[i1-j1,i2-j2,i3-j3,temp-1]+q1[j1,j2,j3,temp-1]*p[i1-j1,i2-j2,i3-j3,temp]+f[j1,j2,j3,temp]*p[i1-j1,i2-j2,i3-j3,temp]) mod 11380; q1[i1,i2,i3,temp]:=(q1[i1,i2,i3,temp-1]+f[i1,i2,i3,temp]) mod 11380; q2[i1,i2,i3,temp]:=(q2[i1,i2,i3,temp-1]+p[i1,i2,i3,temp]) mod 11380; end else if temp=i1+i2+i3 then begin f[i1,i2,i3,temp]:=1; p[i1,i2,i3,temp]:=1; q1[i1,i2,i3,temp]:=q1[i1,i2,i3,temp-1]+1; q2[i1,i2,i3,temp]:=q2[i1,i2,i3,temp-1]+1; end else begin q1[i1,i2,i3,temp]:=q1[i1,i2,i3,temp-1]; q2[i1,i2,i3,temp]:=q2[i1,i2,i3,temp-1]; end; end; begin readln(l3,l2,l1,d); fillchar(f,sizeof(f),0);fillchar(p,sizeof(p),0); fillchar(q1,sizeof(q1),0);fillchar(q2,sizeof(q2),0); if l1+l2+l3<d then writeln(0) else begin main; writeln(p[l1,l2,l3,d]); end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator