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

求助!自己做了很多数据貌似都没有问题,可就是re.

Posted by cactus_ at 2007-07-20 19:09:40 on Problem 1037
代码如下,请帮帮忙,感激不尽!!
program gjk;
  var
    up,down:array[1..20,0..20]of int64;
    n,t:longint;
    c:int64;
    ans,rank:array[1..20]of longint;
  procedure dp;
    var
      i,j:longint;
    begin
      fillchar(up,sizeof(up),0);
      fillchar(down,sizeof(down),0);
      down[1,1]:=1; up[1,1]:=1;
      for i:=2 to 20 do
      for j:=1 to i do begin
        down[i,j]:=down[i,j-1]+up[i-1,j-1];
        up[i,i+1-j]:=down[i,j];
      end;
    end;
  procedure get_a1;
    var
      k:longint;
      sum:int64;
    begin
      k:=1;
      sum:=0;
      while sum+up[n,k]+down[n,k]<c do begin
          sum:=sum+up[n,k]+down[n,k];
          inc(k);
      end;
      ans[1]:=k;  rank[1]:=k;
      c:=c-sum;
    end;
  procedure get_a2;
    var
      k:longint;
      sum:int64;
    begin
      k:=1;
      sum:=0;
      while (k<ans[1])and(sum+up[n-1,k]<c) do begin
          sum:=sum+up[n-1,k];
          inc(k);
      end;
      if k<ans[1] then begin
        ans[2]:=k;
        rank[2]:=k;
        c:=c-sum;
        exit;
      end;
      k:=ans[1];
      while sum+down[n-1,k]<c do begin
          sum:=sum+down[n-1,k];
          inc(k);
      end;
      ans[2]:=k+1;
      rank[2]:=k;
      c:=c-sum;
    end;
  procedure solve;
    var
      i,j,k:longint;
      sum:int64;
    begin
      get_a1;
      get_a2;
      for i:=3 to n do begin
        if ans[i-1]>ans[i-2]
        then begin
             k:=1; sum:=0;
             while sum+up[n+1-i,k]<c do begin
               sum:=sum+up[n+1-i,k];
               inc(k);
             end;
             rank[i]:=k;
             for j:=i-1 downto 1 do if k>=rank[j] then inc(k);
             ans[i]:=k; c:=c-sum;
        end
        else begin
             k:=rank[i-1]; sum:=0;
             while sum+down[n+1-i,k]<c do begin
               sum:=sum+down[n+1-i,k];
               inc(k);
             end;
             rank[i]:=k;
             for j:=i-1 downto 1 do if k>=rank[j] then inc(k);
             ans[i]:=k; c:=c-sum;
        end;
      end;
      for i:=1 to n-1 do write(ans[i],' ');
      writeln(ans[n]);
    end;
  begin
    dp;
    readln(t);
    while t>0 do begin
      readln(n,c);
      solve;
      dec(t);
    end;
  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