ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

To Tran Nam Trung,about 1112
Posted by peng du 13 Oct 2001 10:53
    Can you tell me how to DP?
    thank you.
Re: To Tran Nam Trung --> Here is my source code :
Posted by Tran Nam Trung (trungduck@yahoo.com) 13 Oct 2001 11:05
const
     fi         =       '';
     fo         =       '';
     maxn       =       100;
type
    dt          =       record
      d,c       :       longint;
    end;
var
   f,g          :       text;
   n            :       longint;
   a            :       array[1..maxn] of dt;
   d            :       array[1..maxn] of longint;
   truoc        :       array[1..maxn] of longint;
   max          :       longint;
   li           :       longint;

procedure nhap;
var
   i,tg         :       longint;
   begin
        assign(f,fi); reset(f);
        readln(f,n);
        for i := 1 to n do
        begin
             readln(f,a[i].d,a[i].c);
             if a[i].d > a[i].c then
             begin
                  tg := a[i].d;
                  a[i].d := a[i].c;
                  a[i].c := tg;
             end;
        end;
        close(f);
   end;

procedure sapxep;
var
   i,j          :       longint;
   tg           :       dt;
   begin
        for i := 1 to n - 1 do
          for j := i + 1 to n do
          if a[i].d > a[j].d then
          begin
               tg := a[i];
               a[i] := a[j];
               a[j] := tg;
          end;
   end;

procedure qhd;
var
   i,j          :       longint;
   begin
        max := -1;
        for i := 1 to n do
        begin
             d[i] := 1;
             truoc[i] := 0;
             for j := i - 1 downto 1 do
             if (a[j].c <= a[i].d) and (d[j] + 1 > d[i])
then
             begin
                  d[i] := d[j] + 1;
                  truoc[i] := j;
             end;
             if d[i] > max then
             begin
                  max := d[i];
                  li := i;
             end;
        end;
   end;

procedure truy( i : integer );
   begin
        if truoc[i] <> 0 then truy(truoc[i]);
        writeln(g,a[i].d,' ',a[i].c);
   end;

procedure ghi;
   begin
        assign(g,fo); rewrite(g);
        writeln(g,max);
        truy(li);
        close(g);
   end;

BEGIN
     nhap;
     sapxep;
     qhd;
     ghi;
END.

Some notes : I write this program in Vietnamese. So here
are some translations :
nhap : read_data;
sapxep : sort;
qhd : DP;
ghi : write_output;
Hope you understand !!!
mailto : trungduck@yahoo.com



>     Can you tell me how to DP?
>     thank you.
Hey, is it a good idea to post solution ? I think not.!
Posted by Marat Bakirov 15 Oct 2001 16:47
I think we should better post ideas, and not solutions.
Re: Hey, is it a good idea to post solution ? I think not.! --> Sorry, this is the last time !! :)
Posted by Tran Nam Trung (trungduck@yahoo.com) 15 Oct 2001 18:27
> I think we should better post ideas, and not solutions.