|
|
back to boardWhat's wrong with my program? Please,help me!!! My program: Program t1162;{$N+} Const MaxM=100; Eps=1E-15; Type Point=record S1,S2 :integer; RS1S2 :extended; CS1S2 :extended; RS2S1 :extended; CS2S1 :extended; end; Var N,M,S,i,j :integer; V,CurV :extended; CurS,step :integer; P :array[1..MaxM]of Point; Procedure Rec; var i :integer; predv :extended; begin step:=step+1; if CurS=S then if CurV-V>Eps then begin Writeln('YES'); Halt(0); end; if step>15000 then exit; predv:=curv; for i:=1 to m do if p[i].s1=curs then if curv>p[i].cs1s2 then begin curs:=p[i].s2; curv:=(curv-p[i].cs1s2)*p[i].rs1s2; rec; curv:=predv; curs:=p[i].s1; end; for i:=1 to m do if p[i].s2=curs then if curv>p[i].cs2s1 then begin curs:=p[i].s1; curv:=(curv-p[i].cs2s1)*p[i].rs2s1; rec; curv:=predv; curs:=p[i].s2; end; step:=step-1; end; begin Read(N,M,S,V); for i:=1 to M do read(P[i].S1,P[i].S2,P[i].rS1S2,P[i].cS1S2,P[i].rS2S1,P[i].cS2S1); CurV:=V; CurS:=S; step:=0; Rec; Writeln('NO'); end. Re: What's wrong with my program? Please,help me!!! Well, firstly, it may take more than 15000 steps before a correct solution is found. 15000 is way too little actually... secondly, isn't your solution kind of slow? There's a polynomial time algorithm to solve it. There is a solution of O(m*n), right? Yes, there is an algorithm of O(MN) Re: I don't know this algorithm, but my solution is very fast. You can see it in statistic. > |
|
|