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

haha

Posted by qbcqbc at 2010-03-14 19:58:21 on Problem 1170
var
 a:array[0..7775] of longint;
 i,n,m,i1,i2,i3,i4,i5,p,j,l1,l2,pl,k,k2:integer;
 r:array[1..5,1..3] of integer;
 r1:array[1..5] of integer=(1,6,36,216,1296);
 r2:array[1..5] of integer;
 r3:array[1..999] of integer;
 r4:array[1..5] of integer;
 bo:boolean;
function ans(x:integer):integer;
var
 g:integer;
begin
 g:=1;   ans:=0;
 while x>0 do
  begin
   ans:=ans+r[g,3]*(x div r1[n-g+1]);
   x:=x mod r1[n-g+1];
   g:=g+1;
  end;
end;
function doit1:integer;
var i6:integer;
begin
 doit1:=0;
 for i6:=1 to n do
  doit1:=doit1+r4[i6]*r1[n-i6+1];
end;
function doit2:integer;
var i6:integer;
begin
 doit2:=0;
 for i6:=1 to n do
  doit2:=doit2+(r4[i6]+r2[i6])*r1[n-i6+1];
end;
begin
 fillchar(a,sizeof(a),0);
 fillchar(r3,sizeof(r3),0);
 fillchar(r,sizeof(r),0);
 readln(n);
 for i:=1 to n do
  begin
   readln(r[i,1],r[i,2],r[i,3]);
   r3[r[i,1]]:=i;
  end;
 k2:=0;
 for i:=1 to n do
  k2:=k2+r[i,2]*r1[n-i+1];
 for k:=1 to k2 do
  a[k]:=ans(k);
 readln(m);
 for i:=1 to m do
  begin
   bo:=true;
   fillchar(r2,sizeof(r2),0);
   read(p);
   for j:=1 to p do
    begin
     read(l1,l2);
     if r[r3[l1],2]<l2 then begin bo:=false;break;end;
     r2[r3[l1]]:=l2;
    end;
   readln(pl);
   if bo then
    for i1:=0 to r[1,2]-r2[1] do
     for i2:=0 to r[2,2]-r2[2] do
      for i3:=0 to r[3,2]-r2[3] do
       for i4:=0 to r[4,2]-r2[4] do
        for i5:=0 to r[5,2]-r2[5] do
         begin
          r4[1]:=i1;r4[2]:=i2;r4[3]:=i3;r4[4]:=i4;r4[5]:=i5;
          if a[doit1]+pl<a[doit2] then
          begin
           a[doit2]:=a[doit1]+pl;
          end;
         end;
  end;
 writeln(a[k2]);
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