Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

累死我了。。

Posted by 188230186 at 2009-11-17 07:54:38 on Problem 2794
program double;
 var
  f1,f2:text;
  c:char;
  i,j:integer;
  a:array[1..9,0..4]of char;
  p:array[0..4,0..4,0..4,0..4,0..4,0..4,0..4,0..4,0..4]of boolean;
  f:array[0..4,0..4,0..4,0..4,0..4,0..4,0..4,0..4,0..4]of real;
 function dfs(x1,x2,x3,x4,x5,x6,x7,x8,x9:integer):real;
  var
   sum:real;
   k:integer;
   x:array[1..9]of integer;
  begin
   sum:=0; k:=0;
   if (x1=0)and(x2=0)
      and(x3=0)and(x4=0)
       and(x5=0)and(x6=0)
       and(x7=0)and(x8=0)and(x9=0) then
        begin
         f[x1,x2,x3,x4,x5,x6,x7,x8,x9]:=1;
         dfs:=1;
         exit;
        end;
   if  not p[x1,x2,x3,x4,x5,x6,x7,x8,x9]  then
     begin
      if (a[1,x1]=a[2,x2])and(x1>0)and(x2>0) then begin sum:=sum+dfs(x1-1,x2-1,x3,x4,x5,x6,x7,x8,x9); k:=k+1; end;
      if (a[1,x1]=a[3,x3])and(x1>0)and(x3>0) then begin sum:=sum+dfs(x1-1,x2,x3-1,x4,x5,x6,x7,x8,x9); k:=k+1; end;
      if (a[1,x1]=a[4,x4])and(x1>0)and(x4>0) then begin sum:=sum+dfs(x1-1,x2,x3,x4-1,x5,x6,x7,x8,x9); k:=k+1; end;
      if (a[1,x1]=a[5,x5])and(x1>0)and(x5>0) then begin sum:=sum+dfs(x1-1,x2,x3,x4,x5-1,x6,x7,x8,x9); k:=k+1; end;
      if (a[1,x1]=a[6,x6])and(x1>0)and(x6>0) then begin sum:=sum+dfs(x1-1,x2,x3,x4,x5,x6-1,x7,x8,x9); k:=k+1; end;
      if (a[1,x1]=a[7,x7])and(x1>0)and(x7>0) then begin sum:=sum+dfs(x1-1,x2,x3,x4,x5,x6,x7-1,x8,x9); k:=k+1; end;
      if (a[1,x1]=a[8,x8])and(x1>0)and(x8>0) then begin sum:=sum+dfs(x1-1,x2,x3,x4,x5,x6,x7,x8-1,x9); k:=k+1; end;
      if (a[1,x1]=a[9,x9])and(x1>0)and(x9>0) then begin sum:=sum+dfs(x1-1,x2,x3,x4,x5,x6,x7,x8,x9-1); k:=k+1; end;
      if (a[2,x2]=a[3,x3])and(x2>0)and(x3>0) then begin sum:=sum+dfs(x1,x2-1,x3-1,x4,x5,x6,x7,x8,x9); k:=k+1; end;
      if (a[2,x2]=a[4,x4])and(x2>0)and(x4>0) then begin sum:=sum+dfs(x1,x2-1,x3,x4-1,x5,x6,x7,x8,x9); k:=k+1; end;
      if (a[2,x2]=a[5,x5])and(x2>0)and(x5>0) then begin sum:=sum+dfs(x1,x2-1,x3,x4,x5-1,x6,x7,x8,x9); k:=k+1; end;
      if (a[2,x2]=a[6,x6])and(x2>0)and(x6>0) then begin sum:=sum+dfs(x1,x2-1,x3,x4,x5,x6-1,x7,x8,x9); k:=k+1; end;
      if (a[2,x2]=a[7,x7])and(x2>0)and(x7>0) then begin sum:=sum+dfs(x1,x2-1,x3,x4,x5,x6,x7-1,x8,x9); k:=k+1; end;
      if (a[2,x2]=a[8,x8])and(x2>0)and(x8>0) then begin sum:=sum+dfs(x1,x2-1,x3,x4,x5,x6,x7,x8-1,x9); k:=k+1; end;
      if (a[2,x2]=a[9,x9])and(x2>0)and(x9>0) then begin sum:=sum+dfs(x1,x2-1,x3,x4,x5,x6,x7,x8,x9-1); k:=k+1; end;
      if (a[3,x3]=a[4,x4])and(x3>0)and(x4>0) then begin sum:=sum+dfs(x1,x2,x3-1,x4-1,x5,x6,x7,x8,x9); k:=k+1; end;
      if (a[3,x3]=a[5,x5])and(x3>0)and(x5>0) then begin sum:=sum+dfs(x1,x2,x3-1,x4,x5-1,x6,x7,x8,x9); k:=k+1; end;
      if (a[3,x3]=a[6,x6])and(x3>0)and(x6>0) then begin sum:=sum+dfs(x1,x2,x3-1,x4,x5,x6-1,x7,x8,x9); k:=k+1; end;
      if (a[3,x3]=a[7,x7])and(x3>0)and(x7>0) then begin sum:=sum+dfs(x1,x2,x3-1,x4,x5,x6,x7-1,x8,x9); k:=k+1; end;
      if (a[3,x3]=a[8,x8])and(x3>0)and(x8>0) then begin sum:=sum+dfs(x1,x2,x3-1,x4,x5,x6,x7,x8-1,x9); k:=k+1; end;
      if (a[3,x3]=a[9,x9])and(x3>0)and(x9>0) then begin sum:=sum+dfs(x1,x2,x3-1,x4,x5,x6,x7,x8,x9-1); k:=k+1; end;
      if (a[4,x4]=a[5,x5])and(x4>0)and(x5>0) then begin sum:=sum+dfs(x1,x2,x3,x4-1,x5-1,x6,x7,x8,x9); k:=k+1; end;
      if (a[4,x4]=a[6,x6])and(x4>0)and(x6>0) then begin sum:=sum+dfs(x1,x2,x3,x4-1,x5,x6-1,x7,x8,x9); k:=k+1; end;
      if (a[4,x4]=a[7,x7])and(x4>0)and(x7>0) then begin sum:=sum+dfs(x1,x2,x3,x4-1,x5,x6,x7-1,x8,x9); k:=k+1; end;
      if (a[4,x4]=a[8,x8])and(x4>0)and(x8>0) then begin sum:=sum+dfs(x1,x2,x3,x4-1,x5,x6,x7,x8-1,x9); k:=k+1; end;
      if (a[4,x4]=a[9,x9])and(x4>0)and(x9>0) then begin sum:=sum+dfs(x1,x2,x3,x4-1,x5,x6,x7,x8,x9-1); k:=k+1; end;
      if (a[5,x5]=a[6,x6])and(x5>0)and(x6>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5-1,x6-1,x7,x8,x9); k:=k+1; end;
      if (a[5,x5]=a[7,x7])and(x5>0)and(x7>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5-1,x6,x7-1,x8,x9); k:=k+1; end;
      if (a[5,x5]=a[8,x8])and(x5>0)and(x8>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5-1,x6,x7,x8-1,x9); k:=k+1; end;
      if (a[5,x5]=a[9,x9])and(x5>0)and(x9>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5-1,x6,x7,x8,x9-1); k:=k+1; end;
      if (a[6,x6]=a[7,x7])and(x6>0)and(x7>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5,x6-1,x7-1,x8,x9); k:=k+1; end;
      if (a[6,x6]=a[8,x8])and(x6>0)and(x8>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5,x6-1,x7,x8-1,x9); k:=k+1; end;
      if (a[6,x6]=a[9,x9])and(x6>0)and(x9>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5,x6-1,x7,x8,x9-1); k:=k+1; end;
      if (a[7,x7]=a[8,x8])and(x7>0)and(x8>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5,x6,x7-1,x8-1,x9); k:=k+1; end;
      if (a[7,x7]=a[9,x9])and(x7>0)and(x9>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5,x6,x7-1,x8,x9-1); k:=k+1; end;
      if (a[8,x8]=a[9,x9])and(x8>0)and(x9>0) then begin sum:=sum+dfs(x1,x2,x3,x4,x5,x6,x7,x8-1,x9-1); k:=k+1; end;
     end
      else
       begin
        dfs:=f[x1,x2,x3,x4,x5,x6,x7,x8,x9];
        exit;
       end;
    if k<>0 then f[x1,x2,x3,x4,x5,x6,x7,x8,x9]:=sum/k
            else f[x1,x2,x3,x4,x5,x6,x7,x8,x9]:=0;
    p[x1,x2,x3,x4,x5,x6,x7,x8,x9]:=true;
    dfs:=f[x1,x2,x3,x4,x5,x6,x7,x8,x9];
  end;
 begin
  assign(f1,'double.in'); reset(f1);
  assign(f2,'double.out'); rewrite(f2);
  for i:=1 to 9 do
   begin
    for j:=1 to 4 do
     begin
      read(c);
      a[i,j]:=c;
      read(c);
      read(c);
     end;
    readln;
   end;
  writeln(dfs(4,4,4,4,4,4,4,4,4):0:6);
 end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator